How to set QWidget background color? How to set QWidget background color? python python

How to set QWidget background color?


You need to call setAutoFillBackground(True) on the widget. By default, a QWidget doesn't fill its background.

For more information, see the documentation for the setAutoFillBackground property.

If you want to use an arbitrary background color, you need to modify the widget's palette instead:

p = w.palette()p.setColor(w.backgroundRole(), Qt.red)w.setPalette(p)


you can also use setStyleSheet for example:

w.setAttribute(Qt.Qt.WA_StyledBackground, True)w.setStyleSheet('background-color: red;')