其他分享
首页 > 其他分享> > Qt 之 设置窗口边框的圆角

Qt 之 设置窗口边框的圆角

作者:互联网

在paintEvent事件中绘制窗口边框
这里我们需要重写paintEvent方法,具体代码如下:

void paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing); // 反锯齿;
painter.setBrush(QBrush(Qt::red));
painter.setPen(Qt::transparent);
QRect rect = this->rect();
rect.setWidth(rect.width() - 1);
rect.setHeight(rect.height() - 1);
painter.drawRoundedRect(rect, 15, 15);
//也可用QPainterPath 绘制代替 painter.drawRoundedRect(rect, 15, 15);
{
QPainterPath painterPath;
painterPath.addRoundedRect(rect, 15, 15);
p.drawPath(painterPath);
}
QWidget::paintEvent(event);
}

 

标签:圆角,窗口边框,15,Qt,painterPath,rect,paintEvent,painter
来源: https://www.cnblogs.com/xushenghai19841013/p/14720083.html