One , set up QLabel The color of the font in .

There are several approaches : One is to use setPalette() method ; The second is the use of style sheets ; Fourth, some simple ones can be used HTML style .

The first one , use setPalette() The method is as follows :

...

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

The second kind , Use the style sheet as follows :

setstylesheet("QLabel {color:red;font: bold 14px;}");

// The specific situation can be seen Qt Assistant

The fourth kind , Use some simple ones HTML format :

QLabel *label = new QLabel(tr("Hello Qt!")); QLabel *label = new
QLabel("<h2><i>Hello</i><font color=red>Qt!</font></h2>");
be careful : If you are using a style sheet on the parent window , On child windows, the style sheet of the parent window is used by default , The style sheet picture adapts to the size of the control , And if you use the palette , The picture is not adaptive , Instead, it's full of controls

Two , Font settings

1. QFont font("Arial",30,QFont::Bold); Label->setFont(font); 2.
setStyleSheet("font: bold 14px;");

Three ,QLabel Picture on

1. It can be used setPixmap perhaps setPicture To achieve

QPixmap pix; pix.load("fix.png"); label->setPixmap(pix);
2. It can be used styleSheet realization , Have to say styleSheet Very powerful , Many functions can be realized , Too many names

setStyleSheet("QLabel {border-image:url(:/hello.png);}");

3. This can be done with a palette , It's basically the same as the font

QPalette palette; palette.setBrush(QPalette::Background,
QBrush(QPixmap(":/stateBar.png"))); label->setPalette(palette);

Technology
©2019-2020 Toolsou All rights reserved,
Send love - A little romance for programmers VHDL—— Design of frequency divider Python Implementation of Hanoi Tower code It's over , Starting salary 30khtml+css+js Make a simple website home page QQ Login interface implementation Hill sorting of sorting algorithm ——c++ realization 【 Wechat applet learning 】 Netease music cloud code page implementation details Resume the 13th session python Blue Bridge Cup 2022 Solution to the 13th Blue Bridge Cup ( whole )