1

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.

NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104
SamuelNLP
  • 4,038
  • 9
  • 59
  • 102

2 Answers2

3

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);
}
thuga
  • 12,601
  • 42
  • 52
1

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

NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104