QTableView change row color based on a value
-
30-10-2019 - |
سؤال
I have a QTableView
that I implemented with my own model subclassed from QAbstractTableModel
. I want to be able to change the row color to red when one of the fields in the row has a certain value. I saw a lot of examples where the answer is to call the models setData
and use Qt::BackgroundRole
to change the background color. Since I subclassed the AbstractTableModel
I reimplemented setData
and data
so calling models setData
does nothing with the background color role since I'm only handling data whose role is Qt::DisplayRole
.
I guess my first question is : Is there an easier way to change the color of the entire role? If not, I'm guessing I have to implement that part in setData
and data
to handle the BackgroundRole
which I have no idea how to do so if anyone has examples on how to do this it would really help a lot...
لا يوجد حل صحيح