How to set font size of label on button in Qt?

I use this code to set the label on a button with size 16

ui->pushButton->setText(tr("<font size=16>Tank 1 \n %1%2C</font>").arg(szTemp).arg(degree)); 

but I get the output as <font size=16>Tank 1 005c</font> written on the button.

How to set the font size?

+4
source share
1 answer

The text value of QPushButton not "rich text", so it will not interpret your html as expected. Either use setFont in your widget to set the font size, or set it via the stylesheet:

 QFont font = ui->pushButton->font(); font.setPointSize(16); ui->pushButton->setFont(font); 

Style sheets, while more powerful, can be a little more complicated because it forces you to define a number of other functions that you are currently rewriting.

+8
source

All Articles