PDA

View Full Version : [Qt 4.x] Highliting rows in a QTreeView



Moppel
9th March 2006, 22:51
Hi,

I want to highlight every other row in a QTreeView by changing the background colour for every ohter row.
|one |
|two|
|three|
|four|

I have done this in qt3 by reimplementing



QListViewItem::paintCell( QPainter *p, const QColorGroup &cg,
int column, int width, int alignment )

I have a custom model which I feed into the view.

I just don't find an appropriate pointer where to do it.
In repaint of the view?
Or do I have to use a custom style?

Thanks,

Moppel

jrideout
9th March 2006, 23:25
try myTreeView->setAlternatingRowColors(true);

Moppel
10th March 2006, 10:56
cool, that works! Completely missed that in the doc. Embarrassing!
Thanks.
Seems to have been a so often reimplemented feature that the trolls put it in there API then.

Right, but now, if I want to go further and highlight a row or a even a cell depending on the content of the row/cell.
How can I do this?

wysota
10th March 2006, 11:00
Use different roles from the model. If it's not enough, provide a custom delegate for the view.