Change the selection color of a QTableWidget

2019-02-12 23:09发布

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

标签: qt qt4
1条回答
Root(大扎)
2楼-- · 2019-02-12 23:58

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 }
查看更多
登录 后发表回答