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
Daily Recommendation