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; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
2016-11-04 透光设计
2016-11-04 防拆设计