Bold fonts not working for many fixed-width fonts in linux



  • 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.





  • 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.



  • @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):

    Screenshot_20170408_103415.png



  • 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 kdeglobals

    I deleted all the font settings there and it fixed the issue....strange.



  • @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).



  • @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 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. :)



  • @mikelui What did you change in kdeglobals? I have the same problem with my bold fonts on konsole.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.