Unsolved Setting background colour of qtableview
-
Hi,
I'd like to set a background colour of several lines in a qtableview instance based on an integer value stored in a custom table model. The logic being: if value on column x has a certain magnitude, then set the background to some colour. I read through a lot of posts regarding this issue, but could not figure out, how to do it. More specifically, should I use the custom table model, the paint method of the respective delegate or a (custom?) proxy model for this task or do I indeed need to program all of the above?
Thanks in advance.
Kind regards,
Andreas
-
@andi456
ProbablyQStyledItemDelegate
is the best. But if you don't fancy that you could probably get away with doing it indata()
for the background color role, either directly or through a proxy model. -
If I went the route of the QStyledItemDelegate, I would need to somehow access the respective value from the paint method via the QModelIndex right? In order to understand the internal process. What triggers the paint method of QStyledItemDelegate?
-
@andi456
That's fine,QStyledItemDelegate
seems best.What triggers the paint method of QStyledItemDelegate?
Just whenever it needs painting/re-painting!
QStyledItemDelegate
receives aQModelIndex()
. That contains the row. You can find the "column x" with the desired color viasiblingAtColumn()
in the row.