当前位置:网站首页>设置QCheckbox 样式的注意事项
设置QCheckbox 样式的注意事项
2022-06-26 08:40:00 【liji_digital】
目录
任务
用滑动式按钮显示checkbox的选中和不选中状态。


注意1
为了能显示出按钮的圆角特征,建议图片格式为png格式,这样圆角以外的图片就透明了。
注意2
你可以在qss文件里配置qcheckbox的样式,也可以在代码里直接调用setStyleSheet函数。这里采用后者。
注意3
图片是贴在QCheckbox的方块上的。QCheckbox右边的文字不受影响。
而默认的QCheckbox的方块太小了。图标显示上去很不清楚。所以你要用下面的qss配置方块的尺寸:
QCheckBox::indicator {width: 90px; height: 60px;}注意4
很多的qss示例里面,图片是作为资源文件被引用的,所以要把图片加入qt的资源里面。但是本示例并没有把图片加入资源。而是直接将图片放到构建目录下。setStyleSheet引用的图片路径就是以相对于构建目录而言的。
如下面的路径,是构建目录下的asset

setStyleSheet里面的路径也是相对于构建目录的:
QCheckBox::indicator:unchecked {border-image: url(./asset/on1.png)}假如你使用qss文件配置样式,而你又不想把图片加到资源里面,则应在qss文件内引用相对于qss文件所在目录的路径。
注意5
下面的三行配置要在同一个setStyleSheet中使用,不能采用分开独立的几个setStyleSheet逐个调用,那样的话,前面的调用就无效了。
ui->checkBox->setStyleSheet("QCheckBox::indicator {width: 90px; height: 60px;}"
"QCheckBox::indicator:unchecked {border-image: url(./asset/on1.png) 0 0 0 0 stretch stretch}"
"QCheckBox::indicator:checked {border-image: url(./asset/off1.png) 0 0 0 0 stretch stretch}");
效果

完整源码和可执行程序已经上传到了我的资源基于qt的程序,演示了如何通过setStyleSheet配置checkbox按钮的外观。-C++文档类资源-CSDN下载
边栏推荐
- [300+ continuous sharing of selected interview questions from large manufacturers] column on interview questions of big data operation and maintenance (I)
- How to realize wireless Ethernet high-speed communication for multiple Mitsubishi PLCs?
- cookie session 和 token
- Convex optimization of quadruped
- Checkerboard generation + camera calibration + stereo matching
- 反爬之验证码识别登录 (OCR字符识别)
- 什么是乐观锁,什么是悲观锁
- [unity mirror] use of networkteam
- Speckle denoising method for ultrasonic image
- Some commands for remote work
猜你喜欢

Clion installation + MinGW configuration + opencv installation

百度小程序富文本解析工具bdParse

Isinstance() function usage

Drawing with MATLAB (2) -- color ring

Fourier transform of image

Euler function: find the number of numbers less than or equal to N and coprime with n

Yolov5进阶之一摄像头实时采集识别

Nebula diagram_ Object detection and measurement_ nanyangjx

SQL learning experience (II): question brushing record

20220623 Adobe Illustrator入门
随机推荐
WBC learning notes (I): manually push WBC formula
[QNX Hypervisor 2.2用户手册]12.2 术语(二)
自动化测试中,三种常用的等待方式,强制式(sleep) 、 隐式 ( implicitly_wait ) 、显式(expected_conditions)
Convex optimization of quadruped
phpcms v9商城模块(修复自带支付宝接口bug)
How to set the shelves and windows, and what to pay attention to in the optimization process
上下架和橱窗推荐如何设置,优化过程需要注意的地方
唯品会工作实践 : Json的deserialization应用
【MATLAB GUI】 键盘回调中按键识别符查找表
Stanford doggo source code study
1.21 study logistic regression and regularization
HDU - 6225 Little Boxes(__int128的使用)
关于极客时间 | MySQL实战45讲的部分总结
Nebula diagram_ Object detection and measurement_ nanyangjx
uniapp用uParse实现解析后台的富文本编辑器的内容及修改uParse样式
OpenGL display mat image
Partial summary of 45 lectures on geek time MySQL
什么是乐观锁,什么是悲观锁
Segmentation of structured light images using segmentation network
1.Intro_ Math (white board derivation and reprint of station B)