I am changing the foreground and background color of some of the cells in a QTableWdiget to highlight certain items. I want to later remove the highlighting and restore the default foreground and background colors to the cell, but I'm having trouble doing this.
At the moment I'm resetting the colors to black text on a white background, which will be right on most systems. However, on some systems these will be the wrong colours, e.g. systems using high viability themes where the text is white and the background is black.
I therefore want to find a way to restore the default colors to a cell in the QTableWidget. To do this I tried to backup the default colors before changing them, but this does not save the correct colors:
QColor fgCol = table->item(0, 0)->foreground().color();
QColor bgCol = table->item(0, 0)->background().color();
I also tried this, but it doesn't work either:
QColor fgCol = table->item(0, 0)->data(Qt::ForegroundRole).value<QBrush>().color();
QColor bgCol = table->item(0, 0)->data(Qt::BackgroundRole).value<QBrush>().color();
Is there a way I can restore the default colours to a QTableWidgetItem?
isValid()
), not black... – peppesetData(QVariant(), Qt::BackgroundRole)
or similar? – peppe