原创文章,欢迎转载。转载请注明:转载自 祥的博客
原文链接:https://cloud.tencent.com/developer/article/1596460
- @[toc]1.方法2.分析StyleSheet3.扩展
QLabel的显示圆形
要将一个QLabel
设置为圆形,需要用到QLabel
的函数setStyleSheet()
,修改StyleSheet
就行。
const QString m_red_SheetStyle = "min-width: 16px; min-height: 16px;max-width:16px; max-height: 16px;border-radius: 8px; border:1px solid black;background:red";
const QString m_green_SheetStyle = "min-width: 16px; min-height: 16px;max-width:16px; max-height: 16px;border-radius: 8px; border:1px solid black;background:green";
const QString m_grey_SheetStyle = "min-width: 16px; min-height: 16px;max-width:16px; max-height: 16px;border-radius: 8px; border:1px solid black;background:grey";
const QString m_yellow_SheetStyle = "min-width: 16px; min-height: 16px;max-width:16px; max-height: 16px;border-radius: 8px; border:1px solid black;background:yellow";
ui.lab_LED->setStyleSheet(m_red_SheetStyle);//改成 红色圆形
ui.lab_LED->setStyleSheet(m_green_SheetStyle);//改成 绿色圆形
ui.lab_LED->setStyleSheet(m_grey_SheetStyle);//改成 黄色圆形
ui.lab_LED->setStyleSheet(m_yellow_SheetStyle);//改成 灰色圆形
如果不设置最大最小宽度,高度,QLabel
就变成圆角矩形了。
min-width: 16px; //最小宽度 16px
min-height: 16px; //最小高度 16px
max-width: 16px; //最大宽度 16px
max-height: 16px; //最大高度 16px
border-radius: 8px; //边框是圆角,半径8px
border:1px solid black; //边框1px,边框黑色
background: red; //背景是红色
QLabel的显示圆形: https://cloud.tencent.com/developer/article/1596460
Qt的Layout边缘空白调整: https://cloud.tencent.com/developer/article/1596459
Qt状态栏QStatusBar使用: https://cloud.tencent.com/developer/article/1596465
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有