更改 QTableWidget 的选择颜色
默认情况下,如果 QTableWidget 没有焦点,则所选行的颜色为灰色;如果有焦点,则为橙色。相反,我想将所选行设为红色,无论小部件是否具有焦点。我尝试将其添加到样式表中:
QTableWidget{ selection-background-color: red}
我也尝试过
QTableWidget:edit-focus{ selection-background-color: red}
,
QTableWidget:focus{ selection-background-color: red}
但它们似乎都没有将任何东西变成红色,如果聚焦,它似乎仍然保持橙色,如果不聚焦,它似乎仍然保持橙色。我必须设置哪些属性才能使所选行始终具有相同的颜色,无论它是否具有焦点?
谢谢,
大卫
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你几乎已经拥有了。从技术上讲,您正在调整表格小部件中项目的选择颜色,因此:
应该可以解决问题。
或者:
You almost had it. Technically speaking, you're adjusting the selection color of the items within your table widget, so:
should do the trick.
Alternatively:
background-color
将设置行中项目的背景颜色,selection-color
将设置文本颜色,因为当选择该行时,如果该行中存在文本,则由于颜色的原因,它可能会变得不可读,因此设置正确的文本颜色很重要。#d9fffb:浅蓝色
#000000:黑色
background-color
will set background color of the items in row andselection-color
will set the text color because when the row is selected then if text are present in the row then it might become unreadable due to color so setting proper text color is important.#d9fffb : light blue
#000000 : black