Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Font Size of Button in Qt QML

Tags:

qt

qt-quick

qml

How can the font size of the text in a Button control be set in QML? The designer has not option, and 'font' is not a valid property of Button.

Button {
    id: cmdQuit
    text: qsTr("Quit")
    width: 64
    height: 32
}
like image 849
user1054922 Avatar asked Aug 06 '14 14:08

user1054922


People also ask

How do I change the font for a label in Qt?

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

How do I change the font on QPushButton?

SOLVED How to set the font size of my QPushButton? bu->setStyleSheet("font-size: 20px;"); Or if you are not a fan of qt stylesheet you can extract font of your button, and then change it : QFont font = bu->font(); font.


1 Answers

This is an old question, but since it comes first in search engines I'm providing an update on the situation.

For QtQuick2, unlike what Chris said, you don't need to use the contentItem property anymore. You can access the font property directly from Button.

Example:

Button {
    id: btn
    text: "Test"
    font.pixelSize: 18
}
like image 146
Ad5001 Avatar answered Sep 18 '22 07:09

Ad5001