Qt QWidget绘制圆角注意事项

1、产生黑边

painter.setPen(Qt::NoPen);    //  不设置画笔即可

 

2、背景透明

this->setAttribute(Qt::WA_TranslucentBackground, true);

 

3、大致代码

this->setAttribute(Qt::WA_TranslucentBackground, true);

void widget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    painter.setPen(Qt::NoPen);
    painter.drawRoundedRect(this->rect(), 20, 20);
}

 

posted @ 2022-08-26 13:55  补码  阅读(282)  评论(0)    收藏  举报