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

相关推荐
geovindu36 分钟前
python: Gradient Boosting
开发语言·后端·python·算法·boosting
stormsha1 小时前
MySQL 连不上:2003 / 1045 / 1040 三张面孔与一个排查顺序
java·数据库·mysql
撸码猿1 小时前
老系统只读出口:MySQL 秒级时间戳当水位,3,375 次变更漏 817 行
数据库·mysql·数据一致性·数据同步·增量更新
星夜离尘562 小时前
MATLAB:两路读数平均相差 8 mV,换位能分出传感器偏差和通道偏差吗?
开发语言·matlab
时间的情敌2 小时前
Three.js 水位模拟、水体 Shader、罐体液位动态变化(水箱、水池、储罐液位)
开发语言·javascript·three.js
NendoZen2 小时前
Bubble Tea V2构建Go TUI应用教程
开发语言·golang·xcode
pan_junbiao3 小时前
Go 语言变量的声明与初始化
开发语言·javascript·golang
泡海椒3 小时前
Java 生成接口调用量趋势 PDF:jquick-pdf 多重折线图(JChartType.MultipleLine)落地
java·开发语言·pdf
衡石科技3 小时前
SQL 由模型写出来之后:行级安全在问数链路上的四个注入点
数据库·sql·安全·数据分析