How to color any row of Qtablewidget if cell (row, 1) have text (Total) ?
-
@nabilmk
I wouldn't do it with aQTableWidget
. That is a convenience widget which is aQTreeView
QTableView
plus its own inbuilt model, but you cannot easily change the model's behavior.I would do it with my own
QTreeView
QTableView
and model (e.g.QStandardItemModel
). Then you can subclass the model andoverride
its data() method. There you can returned desired color for the Qt::BackgroundRole or Qt::ForegroundRole roles. You can look at other cells in the row to decide how you want cells colored, so you can see if the first column has text(Total)
or whatever. -
It is a QTableView that underlies a QTableWidget, but @JonB's suggestion is a good one and really only needs to involve the model.