[PyQt] Change background color of section in QHeaderView

Kamp, Peter van der (IMARES) peter.vanderkamp at wur.nl
Tue Jan 31 15:57:46 GMT 2012


Hello,

I have a QTableView with headers. The headers need a different background-color , depending if the items are set to editable. This can be toggled for the entire column by clicking the header. If the items are editable, the header must have a green background, otherwise red. I try to implement it using stylesheets (using ::section:checked). The header changed color, but when I go to the next column (pressing right arrow) the background of the header in that column changes as well. And that's not what I want. I used setHeaderData as well, but that doesn't seem to do anything. What I want is:
Click the header of a certain column once: background of header turns red
Click the header again, background of header turns green.
Other headers must remain the same unless they are clicked too.

What's the best way to solve this problem?

Thanks,

Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20120131/9790fcb3/attachment.html>


More information about the PyQt mailing list