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

相关推荐
yugi9878382 小时前
基于字典缩放的属性散射中心参数提取MATLAB仿真程序
开发语言·matlab
小白学大数据3 小时前
绕过拼多多 App 反抓包机制的综合逆向解决方案
开发语言·爬虫·python·自动化
使者大牙3 小时前
【单点知识】 Python装饰器介绍
开发语言·数据库·python
带土13 小时前
2. C++ private、protected、public
开发语言·c++
我不是8神3 小时前
字节跳动 Eino 框架(Golang+AI)知识点全面总结
开发语言·人工智能·golang
古城小栈3 小时前
Rust复合类型 四大军阀:数、元、切、串
开发语言·后端·rust
kong79069283 小时前
Python核心语法-Python自定义模块、Python包
开发语言·python·python核心语法
数智工坊3 小时前
【操作系统-文件管理】
数据结构·数据库
oioihoii3 小时前
Oracle迁移KingbaseES实战
数据库·oracle
wniuniu_4 小时前
增加依据。。
服务器·网络·数据库