c++设置QLineedit左边de 没有圆角,右边有圆角
时间: 2024-04-30 15:17:35 浏览: 142
你可以使用QLineEdit的QStyleOptionFrameV2类来自定义QLineEdit的边框。下面是一个示例代码,将左边的边框设置为直角,右边的边框设置为圆角。
```c++
void CustomLineEdit::paintEvent(QPaintEvent *event)
{
QLineEdit::paintEvent(event);
QStyleOptionFrameV2 opt;
opt.initFrom(this);
opt.frameShape = QFrame::StyledPanel;
opt.lineWidth = 2;
opt.midLineWidth = 0;
QRect leftRect = style()->subElementRect(QStyle::SE_LineEditContents, &opt, this);
QRect rightRect = style()->subElementRect(QStyle::SE_LineEditContents, &opt, this);
rightRect.setLeft(leftRect.right() + 1);
QPainter painter(this);
// 绘制左边直角的边框
opt.rect = leftRect;
opt.features = QStyleOptionFrameV2::None;
opt.frameRounded = false;
style()->drawPrimitive(QStyle::PE_FrameLineEdit, &opt, &painter, this);
// 绘制右边圆角的边框
opt.rect = rightRect;
opt.features = QStyleOptionFrameV2::None;
opt.frameRounded = true;
style()->drawPrimitive(QStyle::PE_FrameLineEdit, &opt, &painter, this);
}
```
在这个示例中,我们首先使用QLineEdit的paintEvent函数基本上绘制了QLineEdit的所有内容。然后,我们创建了一个QStyleOptionFrameV2对象,通过它来访问QLineEdit的边框样式。我们使用QStyle::subElementRect函数来获取左右两边的矩形框,并设置左边框为直角,右边框为圆角。最后,我们使用QStyle::drawPrimitive函数来绘制QLineEdit的边框。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044736.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)