1.选择器
选择器 | 举例 | 说明 |
---|---|---|
通配符选择器 | * | 匹配任意widget |
类型选择器 | QPushButton | 匹配QPushButton及其子类的实例 |
属性选择器 | QPushButton[flat=“false”] | 匹配属性flat是false的QPushButton实例。其中的属性可以是任何取值支持 QVariant::toString() 的字段。而对属性的取值关系可以是=也可以是~= |
class选择器 | .QPushButton | 匹配QPushButton实例。不包括子类的实例。等价于*[class~=“QPushButton”] |
对象名选择器(或者叫ID选择器 | QPushButton#okButton | 匹配对象名即objectName="okButton"的QPushButton实例 |
后代选择器 | QDialog QPushButton | 匹配QPushButton实例,这些实例都是QDialog的子孙对象,即是QDialog的子控件或子控件的子控件。 |
子选择器 | QDialog>QPushButton | 匹配QPushButton实例,这些实例是QDialog的直接子控件 |
2.对于复杂组件的部分控制
如:
/* 下面这些设置用于设置combox组件的下拉按钮的样式 */
QComboBox::drop-down {
image: url(dropdown.png);
subcontrol-origin: margin;
}
QComboBox::down-arrow {
image: url(down_arrow.png);
}
QComboBox::down-arrow:pressed {
position: relative;
top: 1px; left: 1px;
}
3.根据不同的状态设置样式
如:
QPushButton:hover { color: white }
QRadioButton:!hover { color: red }
QCheckBox:hover:checked { color: white } /* 鼠标悬浮在checkbox上方并且这个checkbox被选中了的样式 */
QPushButton:hover:!pressed { color: blue; } /* 鼠标悬浮在pushbutton上方并且这个按钮没有被按下时的样式 */
QCheckBox:hover, QCheckBox:checked { color: white } /*鼠标悬浮在上方或者被选中时的样式*/
QComboBox::drop-down:hover { image: url(dropdown_bright.png) }