Set Table Cell Color based off Value
Good Day,
My overall goal would be to have the table cell color change based off the current value.
As I am still new to QT Designer I am currently just trying to change the color of an individual cell, but do not seem to be having any luck.
Would anybody be able to point me in the direction of things I should be researching to accomplish this task?
Thanks in advance,
Sarol
Re: Set Table Cell Color based off Value
void QTableWidgetItem::setData ( int role, const QVariant & value ) and look at doc for explanation of roles (Qt::ItemDataRole).
Re: Set Table Cell Color based off Value
You cannot change the colour of individual cell contents from Designer.
The colour of cell content in a QTableView is driven by data returned from the model (with the default delegate). You want your underlying model to return a value in the Qt::ForegroundRole or Qt::BackgroundRole that is based on the value of the cell. Look into the the model/view examples and docs.
You could also address this with a custom delegate attached to the view if it is not appropriate/possible that the model return colour information globally.
Re: Set Table Cell Color based off Value
m.p and ChrisW67,
Thank you for giving me some direction on this matter. I have not worked with the Qt::ForegroundRole or Qt::BackgroundRole yet, but at least its a starting place to research this.
Thanks again,
Sarol