Alex Rivera | Logout

Change the selection color of a QTableWidget

Asked 2011-10-20T18:19:14.557
12

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

Edit
Report

1 Answer

25

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 }
answered 2011-10-20T18:41:33.560

Your Answer