Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the selection color of a QTableWidget

Tags:

qt

qt4

The default is for the selected row to be colored gray if the QTableWidget does not have focus, and orange if it does have focus. I would like to, instead, make the selected row be red whether or not the widget has focus. I tried adding this to the style sheet:

QTableWidget{ selection-background-color: red}

I also tried

QTableWidget:edit-focus{ selection-background-color: red} 

and

QTableWidget:focus{ selection-background-color: red} 

but none of them seem to turn anything red, it still seems to remain orange if focused and gray if not. What properties do I have to set to make the selected row always the same color, whether or not it has focus?

Thanks,

David

like image 477
David Doria Avatar asked Oct 20 '11 18:10

David Doria


1 Answers

You almost had it. Technically speaking, you're adjusting the selection color of the items within your table widget, so:

QTableWidget::item{ selection-background-color: red}

should do the trick.

Alternatively:

QTableWidget::item{ background-color: blue }
QTableWidget::item:selected{ background-color: red }
like image 128
Chris Avatar answered Nov 16 '22 05:11

Chris