QTableWidgetItem has a method for setting the backgroundColor of a cell in the table, but no method for setting the text color of that cell.
How do I change the text color of an arbitrary cell in a QTableWidget
?
Changing the color of text in all cells is as simple as using this stylesheet.
QTableWidget::item {
color: red;
}
But because the API is on the QTableWidget level (rather than QTableWidgetItem level), I find it impossible to target individual cells.
The method is called setForeground()
(not sure how I missed it). Not sure how to do it in CSS only though.
Code:
item = QTableWidgetItem('text')
item.setForeground(QBrush(QColor(0, 255, 0)))
I know it's been a while, but you could try:
QTableWidget::item:selected { color:red; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With