2 Attachment(s)
Change focus/selection color for single cell in QTableView
I have a table that renders a cell background green or red depending on its value. Here's a picture:
Attachment 10715
When I select/focus the table row, the green color is lost:
Attachment 10716
I would like to keep a greenish color only for the single cell on focus/selection. Perhaps I would make it a slightly darker green color. How would I go about doing this?
Here is my code that renders the cell green or red:
Code:
{
...
if (role == Qt::BackgroundRole)
{
if (index.column() == static_cast<int>(Column::STATUS)) {
if (externalDataSource.getStatus(reason) == "OK") {
}
else {
}
}
}
...
}
Re: Change focus/selection color for single cell in QTableView
You create a QStyledItemDelegate subclass that implements paint() the way you want and then attach it to the column of the view with QAbstractItemView::setItemDelegateForColumn()