Bold fonts not working for many fixed-width fonts in linux
-
wrote on 7 Apr 2017, 06:23 last edited by mikelui 4 Jul 2017, 08:56
I'm on Arch Linux using Plasma 5, and noticed my bold fonts stopped working in Konsole. I investigated a bit and noticed this doesn't work:
#include <QApplication> #include <QMainWindow> #include <QPainter> class FontTest : public QWidget { public: void paintEvent(QPaintEvent *) { QPainter p(this); p.setPen(Qt::white); QFont font("Hack"); p.setFont(font); p.drawText(50,50, "Not Bold"); font = p.font(); font.setBold(true); p.setFont(font); p.drawText(50,80, "Bold"); } }; int main(int argc, char *argv[]) { QApplication a(argc, argv); QMainWindow w; FontTest t; w.setCentralWidget(&t); w.setMinimumSize(200, 200); w.show(); return a.exec(); }
Both times the font is not bold. With most sans/sans-serif fonts this is not a problem.
I also see this with Liberation Mono, Nimbus Mono, and several others. The only fixed-width font that works is DejaVu Sans Mono for some reason. If I do a
font.setStyleName("Bold")
then it works as expected. I imagine there's some issue with the font matching. I wanted to see if anyone had any ideas before I decided to make a bug report. My fontconfig is vanilla, with default conf files. I only noticed this problem within the last week.
Right now I'm running Qt 5.8.0
EDIT: tested with the latest dev branch and the problem is still there.
-
wrote on 7 Apr 2017, 18:17 last edited by
Filed a bug report:
-
wrote on 8 Apr 2017, 03:58 last edited by ambershark 4 Aug 2017, 03:59
I'm betting you screwed up your fonts somehow on arch.
I'm running the most recent Arch and that code you posted works fine. I did not test in KDE though I just used xfce since I only had access to my server to test this on right now.
I can test on my arch desktop tomorrow if you think it's an issue though.
Happy to compare environments if you have any questions.
Edit: Tested on Qt 5.8.0.
-
I'm on Arch Linux using Plasma 5, and noticed my bold fonts stopped working in Konsole. I investigated a bit and noticed this doesn't work:
#include <QApplication> #include <QMainWindow> #include <QPainter> class FontTest : public QWidget { public: void paintEvent(QPaintEvent *) { QPainter p(this); p.setPen(Qt::white); QFont font("Hack"); p.setFont(font); p.drawText(50,50, "Not Bold"); font = p.font(); font.setBold(true); p.setFont(font); p.drawText(50,80, "Bold"); } }; int main(int argc, char *argv[]) { QApplication a(argc, argv); QMainWindow w; FontTest t; w.setCentralWidget(&t); w.setMinimumSize(200, 200); w.show(); return a.exec(); }
Both times the font is not bold. With most sans/sans-serif fonts this is not a problem.
I also see this with Liberation Mono, Nimbus Mono, and several others. The only fixed-width font that works is DejaVu Sans Mono for some reason. If I do a
font.setStyleName("Bold")
then it works as expected. I imagine there's some issue with the font matching. I wanted to see if anyone had any ideas before I decided to make a bug report. My fontconfig is vanilla, with default conf files. I only noticed this problem within the last week.
Right now I'm running Qt 5.8.0
EDIT: tested with the latest dev branch and the problem is still there.
wrote on 8 Apr 2017, 17:37 last edited by ambershark 4 Aug 2017, 17:39@mikelui Tested again with my desktop arch and Plasma this time. Same thing, works fine. Qt 5.8.0, latest everything from pacman today.
Again I can help you compare environments but this probably has to do with your font installs or more than likely your theme or kde settings.
Quick test, you can try logging out to a console, move your .config directory, then login to kde again and test it see if it changes. If it does you know it's a kde setting. Then you can just rm -rf your new .config and move your old one back to get your settings back.
Here is a screenshot showing the result (I changed your color to black so it would show up better on my light theme):
-
wrote on 9 Apr 2017, 14:17 last edited by mikelui 4 Sept 2017, 14:39
Well I'll be darned...that indeed works. I tried removing my fontconfig files before, but that didn't change anything.
Do you have any ideas as to which config file would screw with this?
edit:
Turned out to be something in kdeglobalsI deleted all the font settings there and it fixed the issue....strange.
-
Well I'll be darned...that indeed works. I tried removing my fontconfig files before, but that didn't change anything.
Do you have any ideas as to which config file would screw with this?
edit:
Turned out to be something in kdeglobalsI deleted all the font settings there and it fixed the issue....strange.
wrote on 11 Apr 2017, 02:40 last edited by@mikelui Yea I've had KDE configs get screwed up so that's something I do to test whenever I think something might be KDE's fault. :)
Glad you found the offending config file. That's always the hard part if you don't know the kde internals (and most of us don't).
-
wrote on 11 Apr 2017, 23:23 last edited by mikelui 4 Nov 2017, 23:25
@ambershark It turned up again in Kate: https://forum.kde.org/viewtopic.php?f=17&t=139868
I suppose there's some problem when KDE sets the font as Regular instead of just the general font family. Maybe the qFontDatabase ends up looking for a bold version of "Hack Regular" instead of a bold version of "Hack", but I couldn't say for certain.
That was the same line in the kdeglobals that I deleted to get bold working in that basic Qt application in the OP
Thanks for giving me a starting point of where to look!
-
@ambershark It turned up again in Kate: https://forum.kde.org/viewtopic.php?f=17&t=139868
I suppose there's some problem when KDE sets the font as Regular instead of just the general font family. Maybe the qFontDatabase ends up looking for a bold version of "Hack Regular" instead of a bold version of "Hack", but I couldn't say for certain.
That was the same line in the kdeglobals that I deleted to get bold working in that basic Qt application in the OP
Thanks for giving me a starting point of where to look!
wrote on 11 Apr 2017, 23:30 last edited by@mikelui Yea in reading that post you linked it looks like it's the "Regular" part that is causing the issues. Which makes sense as Regular and Bold are mutually exclusive.
But yea, at least you know the problem is on your system with a specific font and not something you have to worry about for your software when it's released. :)
-
@ambershark It turned up again in Kate: https://forum.kde.org/viewtopic.php?f=17&t=139868
I suppose there's some problem when KDE sets the font as Regular instead of just the general font family. Maybe the qFontDatabase ends up looking for a bold version of "Hack Regular" instead of a bold version of "Hack", but I couldn't say for certain.
That was the same line in the kdeglobals that I deleted to get bold working in that basic Qt application in the OP
Thanks for giving me a starting point of where to look!
-
@mikelui What did you change in kdeglobals? I have the same problem with my bold fonts on konsole.
wrote on 19 Oct 2017, 18:44 last edited by@Rendom I'm not sure exactly what it was, I just deleted the whole file and let its defaults get recreated.
For further reference, see this KDE bug report:
https://bugs.kde.org/show_bug.cgi?id=378523The issue seems to intermittently pop back up for me, on ArchLinux