Borders and background of QWidget aren't set by stylesheet

泪湿孤枕 提交于 2019-12-11 04:54:24

问题


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.


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/18257177/borders-and-background-of-qwidget-arent-set-by-stylesheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!