View Full Version : Problem with QHeaderView pseudo-states and stylesheets

5th July 2011, 18:07
Hi !
I'm currently working on a QHeaderView, styling it with a stylesheet. I'm almost done, i just can't find the way to set a background-color to the QHeader::section used for sorting...

In the Qt doc (here (http://doc.qt.nokia.com/latest/stylesheet-examples.html#customizing-qheaderview)), I found this example:

background-color: red;

I tried it but the :checked pseudo-state does not seem to do anything.
What does it do ??
Is there a way to achieve my goal ?


7th July 2011, 17:37
Still stuck with my problem...

7th July 2011, 18:08
It doesn't look like the style sheet supports a different background color for the sort section. The ":checked" pseudo-state has nothing to do with sorting as far as I can tell. The only features available in the style sheet concerning sorting are the ::up-arrow and ::down-arrow.

If you override the QHeaderView:: paintSection() method, you can test to see if the logicalSection argument matches the sortIndicatorSection() and set a different background brush.

What you want to do is non-standard behaviour for tables. In general, the standard approach is to use the sort indicator to show which column is the sort column and in which direction it is sorted.

7th July 2011, 18:33
I wanted to avoid overriding the paintSection()... But if this is the only way i guess I have no choice.

Thx anyway ^^

PS: still don't know what ":checked" do...