How to set the font size of the label on pushbutton in Qt?
Asked Answered
S

3

12

I am using this code to set a label on the pushbutton with size of 16

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

but I am getting the output as <font size=16>Tank 1 005c</font> written on pushbutton.

How to set the font size?

Senhauser answered 21/12, 2012 at 5:37 Comment(0)
H
17

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

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

Style sheets, while more powerful, can tend to be a bit more complex because it forces you to define a number of other features that you are now over-writting.

Hieroglyphic answered 21/12, 2012 at 6:3 Comment(0)
R
7

you can use style sheets

ui->pushButton->setStyleSheet("QPushButton{font-size: 12px;font-family: Arial;color: rgb(255, 255, 255);background-color: rgb(38,56,76);}");
Rasbora answered 26/7, 2018 at 9:56 Comment(0)
P
3

In PyQT5:

from PyQt5.QtWidgets import QPushButton
from PyQt5.QtGui import QFont

# some code here

btn = QPushButton()
btn.setFont(QFont('Times', 20))

# some code here
Pm answered 27/10, 2021 at 1:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.