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);
}

 

上一篇:【Unity学习笔记】Rect Transform组件


下一篇:理顺 JavaScript (15) - 类的继承手段: prototype