QT styleSheet——控件设置样式表

QT开发中,需要设置多种多样的控件表现形式,QT实现的styleSheet能够满足多种多样的场景,这里简单的记录下一些我常用的

  • 设置透明背景,鼠标悬浮时,设置背景色:
cpp 复制代码
pushButton->setStyleSheet("QPushButton {background: transparent;border: none;} QPushButton:hover {background-color: rgba(200, 200, 200, 255);}")
//这里设置pushButton的背景,正常情况下背景设置为透明,当有鼠标悬浮时,设置背景色rgba(200, 200, 200, 255)
  • 根据控件的property值设置对应的背景:
cpp 复制代码
   //widget是一个父控件,他的子对象可以根据property值,设置对应的样式
    widget->setStyleSheet("*[mandatoryField=\"true\"] { background-color: yellow }");
    child1= widget->findChild<QCheckBox*>("EditGroupCB");
    child2= widget->findChild<QComboBox*>("searchDepthCO");
    child1->setProperty("mandatoryField",true); // 背景会设置为黄色
    child2->setProperty("mandatoryField",true); // 背景会设置为黄色

QT官方网站关于styleSheet的介绍点击这里

相关推荐
molaifeng5 小时前
Go 语言如何实现高性能网络 I/O:Netpoller 模型揭秘
开发语言·网络·golang
崇山峻岭之间5 小时前
Matlab学习记录33
开发语言·学习·matlab
Evand J5 小时前
【2026课题推荐】DOA定位——MUSIC算法进行多传感器协同目标定位。附MATLAB例程运行结果
开发语言·算法·matlab
nbsaas-boot5 小时前
SQL Server 存储过程开发规范(公司内部模板)
java·服务器·数据库
zgl_200537795 小时前
ZGLanguage 解析SQL数据血缘 之 Python + Echarts 显示SQL结构图
大数据·数据库·数据仓库·hadoop·sql·代码规范·源代码管理
jllllyuz5 小时前
基于MATLAB的二维波场模拟程序(含PML边界条件)
开发语言·matlab
忆锦紫6 小时前
图像增强算法:Gamma映射算法及MATLAB实现
开发语言·算法·matlab
acaad6 小时前
Redis下载与安装(Windows)
数据库·redis·缓存
玄〤6 小时前
黑马点评中 VoucherOrderServiceImpl 实现类中的一人一单实现解析(单机部署)
java·数据库·redis·笔记·后端·mybatis·springboot
SunflowerCoder6 小时前
EF Core + PostgreSQL 配置表设计踩坑记录:从 23505 到 ChangeTracker 冲突
数据库·postgresql·c#·efcore