Qt QLabel设置字体的颜色

第一种,使用setPalette()方法如下:

1     QLabel *label = new QLabel(tr("Hello Qt!"));
2     QPalette pe;
3     pe.setColor(QPalette::WindowText,Qt::white);
4     label->setPalette(pe);

第二种,使用样式表如下:

1     setStyleSheet("color:red;"); 
2     //setStyleSheet("color:#ff6600;");

第三种,使用QStyle,在Qt Demo中有一个很好的讲解QStyle的例子,可以参考学习。

第四种,使用一些简单的HTML格式:

QLabel *label = new QLabel("<h2><i>Hello</i><font color=red>Qt!</font></h2>");
原文地址:https://www.cnblogs.com/ybqjymy/p/14821782.html