#include class FontSwitcher : public QWidget { public: FontSwitcher(QWidget *parent = nullptr) : QWidget(parent) { fooBar(); } private: QLabel *label_QtVersion; QLabel *label_TimesNewRoman; QLabel *label_TimesNewRomanDB; QLabel *label_NotoSans; QLabel *label_NotoSansDB; QLabel *label_NotoSansDisplay; QLabel *label_NotoSansDisplayDB; void fooBar() { QVBoxLayout *layout = new QVBoxLayout(this); label_QtVersion = new QLabel(QString("Running with Qt %1.%2.%3").arg(QString::number(QT_VERSION_MAJOR), QString::number(QT_VERSION_MINOR), QString::number(QT_VERSION_PATCH))); QFont font_Times("Times", 16); label_QtVersion->setFont(font_Times); layout->addWidget(label_QtVersion); label_TimesNewRoman = new QLabel(" Hello World in Times New Roman."); QFont font_TimesNewRoman("Times New Roman", 16); label_TimesNewRoman->setFont(font_TimesNewRoman); layout->addWidget(label_TimesNewRoman); label_TimesNewRomanDB = new QLabel(" Hello World in Times New Roman DemiBold."); QFont font_TimesNewRomanDB("Times New Roman", 16); font_TimesNewRomanDB.setWeight(QFont::DemiBold); label_TimesNewRomanDB->setFont(font_TimesNewRomanDB); layout->addWidget(label_TimesNewRomanDB); label_NotoSans = new QLabel(" Hello World in Noto Sans."); QFont font_NotoSans("Noto Sans", 16); label_NotoSans->setFont(font_NotoSans); layout->addWidget(label_NotoSans); label_NotoSansDB = new QLabel(" Hello world in Noto Sans DemiBold."); QFont font_NotoSansDB("Noto Sans", 16); font_NotoSansDB.setWeight(QFont::DemiBold); label_NotoSansDB->setFont(font_NotoSansDB); layout->addWidget(label_NotoSansDB); label_NotoSansDisplay = new QLabel(" Hello World in Noto Sans Display."); QFont font_NotoSansDisplay("Noto Sans Display", 16); label_NotoSansDisplay->setFont(font_NotoSansDisplay); layout->addWidget(label_NotoSansDisplay); label_NotoSansDisplayDB = new QLabel(" Hello world in Noto Sans Display DemiBold."); QFont font_NotoSansDisplayDB("Noto Sans Display", 16); font_NotoSansDisplayDB.setWeight(QFont::DemiBold); label_NotoSansDisplayDB->setFont(font_NotoSansDisplayDB); layout->addWidget(label_NotoSansDisplayDB); } }; int main(int argc, char *argv[]) { QApplication app(argc, argv); FontSwitcher window; window.setWindowTitle("Qt Font Example"); window.show(); return app.exec(); }