View Full Version : QPainter with TreeView

25th September 2008, 01:25
If I override drawRow() in my QTreeView subclass and place only a call to the base class's drawRow, and pass the same parameters I received, the tree will draw normally.

If I take the QPainter parameter and call setPen(Qt::red) followed by base::drawRow(), the tree will draw normally except for items with children. Those items will have the '+' or '-' expansion symbol drawn in red. The text is not red.

I don't understand why drawRow takes a QPainter parameter if it doesn't use it. Calling the item delegate's paint() draws the text in the wrong location but in the same default color.

25th September 2008, 08:04
It does use the painter.
However, it is possible that a setting is overwritten e.g. when a style's value is used. The colors returned in your model's data function will also (at some time) be set in the QPainter.

Therefore, if you want to change that colors,
* use a (Proxy)Style. (Search forum for details).
* use a style sheet