Qt ------ stylesheet 样式

1、所有的窗口组件都可以用 setStyleSheet() 设置样式

2、使用样式,显示效果可以不受平台影响,比如保证window 7 和 linux 显示效果是一样的

QVariant

 

 

如果 style.qss 和 icon 在同一个 res.qrc,修改 style.qss 的内容不会更新到显示效果上,单独建一个XXX.qrc 就可以了

style.qss 改为 style.css 更好,因为 XXX.css 使用 Qt creator 或者 Notepad++ 编辑,关键字可以高亮

添加到 Resources 的好处是可以把 XXX.qss 编译进exe文件

样式语法:

QPushButton, QLineEdit, QComboBox { color: red; background-color: white }

样式规则由 selector 和 declaration 两部分组成,QPushButton 是 selector;color: red 是 declaration;color 是 property

在 Qt assistant 里“Qt style sheets reference”的“List of Properties”介绍哪些 properties 可以用在哪些控件上

部分 property 含义解释:

selection-color:被选中的文字的颜色

selection-background-color:被选中的字体的背景颜色

border-radius:把长方形的四个直角圆角化

好看样式收集:

QPushButton {
    border-left-width: 0px;
    border-top-width: 0px;
    border-bottom-width: 3px;
    border-right-width: 3px;
    border-style: outset;
    border-radius: 5px;
    border-color: black;
}
QPushButton:hover {
    border-color: red;
}
QPushButton:pressed {
    border-left-width: 3px;
    border-top-width: 3px;
    border-bottom-width: 0px;
    border-right-width: 0px;
    border-color: black;
}
原文地址:https://www.cnblogs.com/god-of-death/p/7782947.html