QT5如何设置QLabel中字体的颜色
2024-08-31 10:25:44
修改了wd的文章:
如何使用Qt5,设置QLabel中字体的颜色。
大致有几种做法:
一是使用setPalette()方法;
二是使用样式表;
三是可以使用QStyle;
四是可以在其中使用一些简单的HTML样式。
第一种,使用setPalette()方法如下:
QPalette pe;
pe.setColor(QPalette::WindowText, Qt::red);
QLabel *label = new QLabel(this);
label->setPalette(pe);
label->setText("Hello World");
第二种,使用样式表如下:
QLabel *label = new QLabel(this);
label->setStyleSheet("background-color: rgb(250, 0, 0);font-size:60px;color:blue");
label->setText("Hello World");
第三种,使用QStyle
第四种,使用一些简单的HTML格式:
QLabel *label = new QLabel(tr("Hello Qt!"));
QLabel *label = new QLabel("<h2><i>Hello</i><font color=red>Qt!</font></h2>");
Warning: Some styles do not use the palette for all drawing, for instance, if they make use of native theme engines. This is the case for both the Windows XP, Windows Vista, and the Mac OS X styles.
Style sheets let you perform all kinds of customizations that are difficult or impossible to perform using QPalette alone
所以尽量使用方法二
最新文章
- Windows上安装使用MongoDB(一)
- nginx的worker_processes,worker_cpu_affinity及worker_connections
- 51NOD 算法马拉松12
- xdebug初步
- js实现收缩菜单效果
- 基于UDP协议的多路广播地址
- Android发展简报
- iOS7 初体验
- 24 AIDL案例
- 自定义AlertDialog(仿微信)
- 学习笔记之form表单
- Java内存管理-程序运行过程(一)
- DER、CRT、CER、PEM格式的证书及转换
- webSocket开发chat application过程
- 发送html内容的email(转)
- linux fack 文件系统修复命令
- JavaScript设计模式与开发实践:分时函数
- iOS 解决上传100张图片内存奔溃问题
- 多线程设计模式(三):Master-Worker模式
- contentType 应用,(表中数据大量存在外键时使用)