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

相关推荐
xsc699675几秒前
Milvus实战:快速上手向量数据库
数据库·milvus
艾莉丝努力练剑几秒前
【Qt】事件
服务器·开发语言·网络·数据库·qt·tcp/ip·计算机网络
PersistJiao1 分钟前
python环境下免费、专业的中英翻译
开发语言·windows·python·机器翻译
rqtz3 分钟前
【C++】源码编译 Qt5.15.3|Ubuntu22.04 下 ROS 开发环境搭建
开发语言·c++·qt·ros
Bert.Cai3 分钟前
Oracle简介
数据库·oracle
Jun6264 分钟前
QT(9)-Qjson移植
开发语言·qt
施棠海4 分钟前
自定义并可深度定制的数字滚动选择器完整源代码与相关注意事项
java·开发语言
名不经传的养虾人7 分钟前
从0到1:企业级AI项目迭代日记 Vol.41|多租户不是一个功能,是一次手术
服务器·数据库·系统架构·ai编程·ai工作流·企业ai
z落落9 分钟前
C# 索引器 this[]
开发语言·c#
csdn_aspnet13 分钟前
C# List 移除某个属性值中最大的值
开发语言·c#·list