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的介绍点击这里

相关推荐
m0_7434703738 分钟前
使用Python进行PDF文件的处理与操作
jvm·数据库·python
Demon_Hao1 小时前
JAVA通过Redis实现Key分区分片聚合点赞、收藏等计数同步数据库,并且通过布隆过滤器防重复点赞
java·数据库·redis
Dxy12393102161 小时前
JS发送请求的方法详解
开发语言·javascript·ecmascript
sw1213891 小时前
C++中的代理模式实战
开发语言·c++·算法
難釋懷1 小时前
Lua语法入门-条件控制、函数
开发语言·junit·lua
掘根1 小时前
【微服务即时通讯】消息转发子服务
数据库·oracle
喜欢喝果茶.1 小时前
SQL 预处理
数据库·sql
桌面运维家1 小时前
Win10打印机共享故障排查:权限与网络配置详解
开发语言·网络·php
Sunshine for you2 小时前
实时操作系统中的C++
开发语言·c++·算法
史蒂芬_丁2 小时前
C++深度拷贝例子
java·开发语言·c++