orodbhen
orodbhen

Reputation: 2694

PyQt4: restrict stylesheet to parent

So, first off, I've already read this, and everything I can find online says the same thing. To restrict the scope of a stylesheet setting do this:

self.setObjectName( self._TAG )
self.setStyleSheet( "#{} {{ background-color:{}; }}".format( self._TAG, "#d5d5d5" ) )

Where self is an object derived from QFrame. The problem is that, at least in the case of objects derived from QFrame, it only excludes children that don't descend from QFrame. The buttons and checkboxes retain the default color, but the QLabels inherit from the parent.

So is there any way around this, other than explicitly specifying the stylesheet for each child?

Upvotes: 1

Views: 251

Answers (1)

Jean-Sébastien
Jean-Sébastien

Reputation: 2697

You have to set the autoFillBackground property of the Qlabel to True, otherwise, the label won't paint its background:

myqlabel.setAutoFillBackground(True)

Upvotes: 1

Related Questions