[Qt-interest] How can I assign a QSS pseudo-state to my own object?

Girish Ramakrishnan girish at forwardbias.in
Fri Oct 23 16:19:01 CEST 2009


Paul Colby wrote:
> I like the QSS pseudo-state concept... it works very well for many Qt classes.
> 
> Is it possible to assign pseudo-states to my own custom widgets?
> Specifically, have some logic that tracks which of a set of custom
> widgets is "selected", and would like to be able to set the
> ":selected" pseudo state for that widget.
> 
> So then I could use QSS like:
> 
> MyWidget {
>   ...
> }
> 
> MyWidget:selected {
>   ...
> }
> 
> Is this possible with Qt 4.5/4.6?
> 

Writing QSS for custom widgets is not really supported.

You can make it work though the following cases :
1. If your widget can be completely styled using QStyle and it uses
primitives, controls that are already defined in QStyle (i.e if you
define your own elements, it won't work).

2. If you are only looking for colors/brushes, you can set the
stylesheet and your widget's palette() will have the appropriate brushes.

Girish



More information about the Qt-interest-old mailing list