Qt4 style sheet 自定义属性选择器selector
来源:互联网 发布:序列号管理网站源码 编辑:程序博客网 时间:2024/05/16 08:35
Qt4 style sheet 自定义属性选择器selector
现在项目的GUI里style设置基本都通过stylesheet来做的,里面有几个比较好用的记下来。
在Qt帮助文档里,stylesheet的语法里有通过selector来设置style的方法,其中有两个有意思的是:
Property SelectorQPushButton[flat="false"]Matches instances of QPushButton that are not flat . You may use this selector to test for any Qt property that supports QVariant::toString () (see the toString() function documentation for details). In addition, the special class property is supported, for the name of the class.
This selector may also be used to test dynamic properties. For more information on customization using dynamic properties, refer to Customizing Using Dynamic Properties .
Instead of = , you can also use ~= to test whether a Qt property of type QStringList contains a given QString .
Warning: If the value of the Qt property changes after the style sheet has been set, it might be necessary to force a style sheet recomputation. One way to achieve this is to unset the style sheet and set it again.
ID SelectorQPushButton#okButtonMatches all QPushButton instances whose object name is okButton .第二个是通过object name来判断
比如QTMyWidget里定义了一个 QLabel* m_pLabelName;
给它设置一个objectname: m_pLabelName->setObjectName("Name");
然后就可以通过在CSS文档里添加下面的代码来set style
QTMyWidget QLabel#Name { background: none; color: white; }QTMyWidget QLabel#Name { background: none; color: white; }回头重点强调第一个通过Property Selector来set style, 这一点可以跟自定义Property结合起来,功能强大。
QWidget已经有了很多默认的Property,我们还可以通过Qt宏Q_PROPERTY给widget添加自定义的Property,
Q_PROPERTY宏的定义:
Q_PROPERTY(type name
READ getFunction
[WRITE setFunction]
[RESET resetFunction]
[DESIGNABLE bool]
[SCRIPTABLE bool]
[STORED bool]
[USER bool])使用比如
class QTMyWidget : public QFrame { Q_OBJECT Q_PROPERTY(bool active READ active WRITE setActive) ... public: bool active()const; void setActive(bool active); private: bool m_bActive; }QTMyWidget[active="true"] { border-width: 4px 4px 4px 4px; }这样就能设置QTMyWidget在active == true时的style了。
- Qt4 style sheet 自定义属性选择器selector
- 如何自定义`Selector`状态选择器
- Cascading Style Sheet (css) 的Expression 属性
- Qt Style Sheet自定义QSlider
- Qt Style Sheet自定义QSlider
- 自定义属性、Style、Theme
- android shape selector style属性心的
- Style sheet
- Decalre-style Android自定义属性
- qt slider scroll bar 进度条 自定义(通过style sheet)
- 选择器selector
- selector 选择器
- selector选择器
- 选择器selector
- selector选择器
- Selector选择器
- 监听Touch事件自定义属性实现Selector
- 自定义控件用属性实现selector效果
- AWK单行脚本快速参考
- Linux P2P音视频聊天系统实现步骤
- 怎么修改如何修改MySQL 5.1 data文件夹路径
- 整流电路
- 计算日期的shell程序
- Qt4 style sheet 自定义属性选择器selector
- css全局样式表
- 创建Android HelloWorld工程
- 关于实际设计串、并联电路的小技巧
- 数组/集合(ArrayList)/泛型
- Qt中如何使用样式表QPalette以及相关注意事项
- 《软件测试基本功》系列教程
- 关于在 aix 启动 时候, 启动特定服务
- 输入函数