赞
踩
- 样式表语法,选择器{属性1:值;属性2:值;}
- 如果只有单个属性,分号可以不加
选择器 | 示例 | 描述 |
---|---|---|
通用选择器 | * | 匹配所有控件 |
类型选择器 | QPushButton | 匹配给定的控件,包括子类 |
类选择器 | .QPushButton | 匹配给定的控件,不包括子类 |
属性选择器 | QPushButton[flat=“false”] | 匹配给定类型中符合[属性]的控件 |
ID选择器 | QPushButton#closeButton | 匹配给定类型,且对象名为closeButton的控件 |
子孙对象选择器 | QDialog QPushButton | 匹配给定类型的子孙控件 |
子对象选择器 | QDialog>QPushButton | 匹配给定类型的直接子控件 |
辅助[子控件]选择器 | QComboxBox::drop-down | 复杂对象子控件 |
伪状态选择器 | QPushButton:hover | 控件的特定状态下的样式 |
并集选择器 | QPushButton,QLineEdit | 若干基础选择器可以写一起,逗号隔开 |
QPushButton[down = "false"]{color:yellow;background:red}
QLabel[text = "TextLabel"]{color:red}
同时在UI和文件代码里设置样式表会冲突,只会生效ui里设置的
QPushButton:hover{color:red}
状态 | 描述 |
---|---|
:disabled | 控件禁用 |
:enabled | 控件启用 |
:focus | 控件获取输入焦点 |
:hover | 鼠标在控件上悬停 |
:pressed | 鼠标按下 |
:checked | 控件被选中 |
:unchecked | ~ |
:indetetminate | 控件部分被选中 |
:open | 控件打开 |
:closed | ~ |
:on | 控件可以切换,且处于on状态 |
:off | ~ |
! | 对以上状态的否定 |
QLabel#label{ font-family: "微软雅黑"; font-size: 20px; font-style: italic; color: rgb(239,204,180); border-image:url("C:/Users/PVer/Pictures/Resource/派蒙.jpeg") } QPushButton{ /*上右下左设置padding间距*/ padding:20px 0px 0px 50px; border: 3px solid black; border-radius: 10px; background-color:red; } QLineEdit{ border-top:2px solid yellow; border-right:2px dotted black; border-top-left-radius:10px; border-left:3px solid black; } QLabel#label_2{ background-image:url("C:/Users/PVer/Pictures/Resource/xiaoku.png"); background-repeat:no-repeat; background-position:left top; } QLabel#label_2:hover{ background-color:green; } QPushButton:pressed{ background-color:orange; } QCheckBox::indicator{ background-color:grey; border-radous:5px; } QCheckBox::indicator:checked{ background-color:black; } QCheckBox::indicator:!checked:hover{ background-color:green }
.细节、注意事项
void CustomWidget::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}
而且必须使用Q_OBJECT宏
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。