Borders and background of QWidget aren't set b

2019-08-12 05:33发布

I've set the stylesheet of a QWidget to change the borders and the background,

#gui {
    border: 4px inset #515c84;
    border-radius: 9px;
    background-image: url(./back.png)
}

Its name is gui but neither border nor background are shown.

2条回答
2楼-- · 2019-08-12 05:37

Override paintEvent in your QWidget subclass like this:

void MyWidget::paintEvent(QPaintEvent *e)
{
    QStyleOption opt;
    opt.init(this);
    QStylePainter p(this);
    p.drawPrimitive(QStyle::PE_Widget, opt);
}
查看更多
戒情不戒烟
3楼-- · 2019-08-12 05:44

For the Python-QT bindings (PyQt, PySide) just setting the attribute WA_StyledBackground on the QWidget is enough to show border and background.

查看更多
登录 后发表回答