Skip to content Skip to sidebar Skip to footer

Pyqt5: Stylesheet And Inheritance From Qwidget

My code generates a Window containing two QWidgets, a red (wg1) and a blue (wg2) one. If they become Fields (commented out) which inherits from QWidget, their color disappears. My

Solution 1:

The explanation resides in the section related to QWidget of the stylesheet reference:

If you subclass from QWidget, you need to provide a paintEvent for your custom QWidget as below:

By default, QWidget does that by default, but QWidget subclasses do not, so you either set the flag or you implement the paintEvent.

In any case, consider using stylesheet selectors and avoid generic/universal syntax as they often result in unexpected behavior for complex child widgets.

Post a Comment for "Pyqt5: Stylesheet And Inheritance From Qwidget"