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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值