[Qt-jambi-interest] Palette behaving differently when assigning stylesheet

Eskil Abrahamsen Blomfeldt eblomfel at trolltech.com
Fri May 29 10:03:47 CEST 2009


Danny Sporea wrote:
>  
> I have a dialog with a QListWidget with items and a button. When the button is pushed, the palette of the QListWidget is changed. Everything works fine, unless I apply a stylesheet to the dialog. After that, pushing the button does not produce the same results anymore. Unfortunately this is just a simple example, mine is a lot more complicated and cannot achieve the desired results using a stylesheet on the QListWidget, as opposed on using the palette. Is there a way to block a child widget on receiving the parent stylesheet and messing up the setPalette and allow normal palette behaviour when palette is changed ?
>   
Hi, Danny.

Using widget palettes and style sheets together is not actually 
supported by Qt, so there will be some inconsistencies when trying to do 
this.

In your case what is happening is that the style sheet is preventing the 
palette from being propagated from the list view to its viewport, hence 
the viewport will not turn red, only the frame around it. To work around 
it in your specific case, you can use the following code:

    ui.lst.viewport().setPalette(RED_QPALETTE);

Please note, however, that since this is documented to be an unsupported 
combination of two styling models, there is no guarantee that the 
behavior will not change in later versions.

--  Eskil



More information about the Qt-jambi-interest mailing list