如何在 QTableView 中为当前项设置样式表 [英] How to set stylesheet for the current item in QTableView

查看:67
本文介绍了如何在 QTableView 中为当前项设置样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

QTableView 编辑控件对当前项目可见时,编辑的 shylesheet 发生.当 QTableView 中没有活动编辑控件时,当前项使用 QTableView { selection-background-color: } 如何为当前项设置不同的样式?

解决方案

Qt 样式表支持子控件和伪状态,您可以使用它来改进您的自定义.(参见

When QTableView edit control is visible for the current item the shylesheet of the edit takes place. When there is no active edit control in the QTableView the current item is styled using the QTableView { selection-background-color: } How to set different style only for the current item?

解决方案

Qt style sheets support sub-controls and pseudo states, you can use it to improve your customization. (see http://qt-project.org/doc/qt-5/stylesheet-reference.html#list-of-pseudo-states )

In this case you can use the ::item sub-control and the :focus pseudo state (the "current" pseudo state doesn't exist, but the :focus does the same).

This is an example that you can use:

QTableView::item:focus
{
   selection-background-color: yellow;
}

See also http://qt-project.org/doc/qt-5/stylesheet-examples.html#customizing-qtreeview

这篇关于如何在 QTableView 中为当前项设置样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆