QLabel displays bold text as non-bold from a certain size on
-
Hi all :-)
When using a
QLabelto display large bold text, the text isn't bold anymore from a certain font size on.Minimal example:
main.cpp:#include "MainWindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication app(argc, argv); MainWindow mainWindow; mainWindow.show(); return app.exec(); }MainWindow.h:#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(); }; #endif // MAINWINDOW_HMainWindow.cpp:#include "MainWindow.h" #include <QVBoxLayout> #include <QLabel> MainWindow::MainWindow() { auto *centralWidget = new QWidget; auto *layout = new QVBoxLayout(centralWidget); setCentralWidget(centralWidget); auto labelFont = font(); labelFont.setBold(true); auto *label1 = new QLabel(tr("Bold text")); labelFont.setPointSize(47); label1->setFont(labelFont); layout->addWidget(label1); auto *label2 = new QLabel(tr("Bold text")); labelFont.setPointSize(48); label2->setFont(labelFont); layout->addWidget(label2); }This is the output:

As you can see,
label1has a point size of47, and the text is, as it should be, bold.label2is one point bigger, and the text isn't displayed bold anymore.So … is this a bug or a feature?! ;-)
Thanks for all help!
Cheers, Tobias
-
@mpergand I just tried it with another machine where "Noto Sans" was selected from the beginning. Same issue, from a certain size on, the bold text was displayed non-bold. But after having changed the font to something else and back to "Noto Sans", the issue was gone.
Maybe some strange configuration problem caused by an years old KDE profile and some updates?!
Strange, but could be fixed by simply playing around with the font settings.
Thanks for testing this however :-)
-
Hi all :-)
When using a
QLabelto display large bold text, the text isn't bold anymore from a certain font size on.Minimal example:
main.cpp:#include "MainWindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication app(argc, argv); MainWindow mainWindow; mainWindow.show(); return app.exec(); }MainWindow.h:#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(); }; #endif // MAINWINDOW_HMainWindow.cpp:#include "MainWindow.h" #include <QVBoxLayout> #include <QLabel> MainWindow::MainWindow() { auto *centralWidget = new QWidget; auto *layout = new QVBoxLayout(centralWidget); setCentralWidget(centralWidget); auto labelFont = font(); labelFont.setBold(true); auto *label1 = new QLabel(tr("Bold text")); labelFont.setPointSize(47); label1->setFont(labelFont); layout->addWidget(label1); auto *label2 = new QLabel(tr("Bold text")); labelFont.setPointSize(48); label2->setFont(labelFont); layout->addWidget(label2); }This is the output:

As you can see,
label1has a point size of47, and the text is, as it should be, bold.label2is one point bigger, and the text isn't displayed bold anymore.So … is this a bug or a feature?! ;-)
Thanks for all help!
Cheers, Tobias
-
@JonB Oh, sorry ;-) It's Qt 5.15.11 on KDE/X. But I also get the very same result compiling the code against Qt 6.5.3.
-
@l3u_
Also does your windowing system have some "font viewer" where you could see how this behaves outside of Qt? I doubt whatever the issue that Qt code handles a point size >= 48 specially. -
@JonB
labelFont.family()says it's "DejaVu Sans", also according to my KDE settings.Here's what LibreOffice displays (as expected) when using this font and setting the same font sizes:

although the rendering looks a bit different … -
This is odd … seems to depend on the used font.
Happens with DejaVu, doesn't happen if I set it to e.g. "Arimo" or "Noto Sans".
Question is: Why?!
-
@mpergand I just tried it with another machine where "Noto Sans" was selected from the beginning. Same issue, from a certain size on, the bold text was displayed non-bold. But after having changed the font to something else and back to "Noto Sans", the issue was gone.
Maybe some strange configuration problem caused by an years old KDE profile and some updates?!
Strange, but could be fixed by simply playing around with the font settings.
Thanks for testing this however :-)
-
L l3u_ has marked this topic as solved on
