[PyQt] Custom widgets, dynamic properties and css

Richard Smith richard at omniaccess.com
Tue Nov 20 12:58:09 GMT 2007


Hi Guys,

I've created a custom widget for an application I'm building.

The widget is a simple frame with 2 labels inside it.

Basically, I need the frame style to change dependant on a property of
the custom widget. I've set the property using .setProperty() method,
and the initial style of the widget is fine.

For each state of the property, the widget has a style.

However, as the application progresses through it's run, the custom
property changes as to the state, however the style doesn't change.

I have a couple of methods that are used to change the state and I am
calling update() after the change, but the style still doesn't change.

The important bits of the widget are:

class QuickStatus(QtGui.QFrame):
        def __init__(self, parent=None):
                QtGui.QWidget.__init__(self, parent)
		## { ... snip ... }

        def getState(self):
                return int(self.property("state").toString())

        def setState(self, state):
                if state in STATES:
                        self.setProperty( "state",
                                          QtCore.QVariant(state))
                        self.update()

Then for each of the various states I've got the following styles:

QuickStatus[state="1"]
{
 background-color: #CCFF99;
 border: 1px solid green;
}

Anyone have any hints as to why the style of the control isn't being
updated as the state changes? Am I missing something crucial?

-- 
Richard


More information about the PyQt mailing list