PDA

View Full Version : QHeaderview and backgroundColorRole



snydesc
21st February 2013, 21:53
I have a table view and I need a way to set the color of a row header for a particular row. Note that some row headers may have different colors. In my model in the headerData() function I handle the case of QBackgroundRole and QBackgrounColorRole. Neither of them do anything. How do you specify the color of a row header?

Thanks.

wysota
21st February 2013, 23:54
QHeaderView does not respect BackgroundRole. If you want to color a header, you have to do that yourself by reimplementing the header section drawing routine.

snydesc
21st February 2013, 23:57
But the documentation says: QHeaderView respects the following item data roles: TextAlignmentRole, DisplayRole, FontRole, DecorationRole, ForegroundRole, and BackgroundRole.

wysota
22nd February 2013, 00:00
Hmm.... indeed. In that case please provide a minimal compilable example reproducing the problem.

snydesc
22nd February 2013, 00:08
OK I found out what is happening. There was a style being applied to QHeaderView::section. Apparently if you apply a style you can't override it within the model. This is problematic as I would would like all rows to be styled the same color and then have the model determine if the row colors should change. Any ideas?

bisasatan
24th May 2013, 15:36
I am facing the same Problem right now - I would like to have a verticalHeader with alternatingRowcolors, while you can set this option to true it does not work and there seems to be no way to set the backgroundcolor for specific HeaderItems - no one has an Idea, or maybe you have solved the problem by now?