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);

©2019-2020 Toolsou All rights reserved,
( Essence )2020 year 6 month 29 day C# Class library Interface signature verification Mybatis Mapping file Mapper.xml in # and $ The difference between ( Essence )2020 year 8 month 13 day C# Basic knowledge windform Realize two color sphere MySql sentence Recursively find all subordinate departments of an input department mybatis-config.xml Set default value configuration use PyMC3 Bayesian statistical analysis was performed ( code + example )org.postgresql.util.PSQLException Processing records vue use THREE.js Create a cube that you can control @Repository The role of annotations ( Essence )2020 year 6 month 26 day C# Class library Exception handling help class