Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Bold fonts not working for many fixed-width fonts in linux
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 6.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mikelui
    wrote on 7 Apr 2017, 06:23 last edited by mikelui 4 Jul 2017, 08:56
    #1

    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.

    A 1 Reply Last reply 8 Apr 2017, 17:37
    0
    • M Offline
      M Offline
      mikelui
      wrote on 7 Apr 2017, 18:17 last edited by
      #2

      Filed a bug report:

      https://bugreports.qt.io/browse/QTBUG-59993

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ambershark
        wrote on 8 Apr 2017, 03:58 last edited by ambershark 4 Aug 2017, 03:59
        #3

        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.

        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

        1 Reply Last reply
        3
        • M mikelui
          7 Apr 2017, 06:23

          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.

          A Offline
          A Offline
          ambershark
          wrote on 8 Apr 2017, 17:37 last edited by ambershark 4 Aug 2017, 17:39
          #4

          @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

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          1 Reply Last reply
          3
          • M Offline
            M Offline
            mikelui
            wrote on 9 Apr 2017, 14:17 last edited by mikelui 4 Sept 2017, 14:39
            #5

            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.

            A 1 Reply Last reply 11 Apr 2017, 02:40
            1
            • M mikelui
              9 Apr 2017, 14:17

              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.

              A Offline
              A Offline
              ambershark
              wrote on 11 Apr 2017, 02:40 last edited by
              #6

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

              My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mikelui
                wrote on 11 Apr 2017, 23:23 last edited by mikelui 4 Nov 2017, 23:25
                #7

                @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!

                A R 2 Replies Last reply 11 Apr 2017, 23:30
                0
                • M mikelui
                  11 Apr 2017, 23:23

                  @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!

                  A Offline
                  A Offline
                  ambershark
                  wrote on 11 Apr 2017, 23:30 last edited by
                  #8

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

                  My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                  1 Reply Last reply
                  0
                  • M mikelui
                    11 Apr 2017, 23:23

                    @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!

                    R Offline
                    R Offline
                    Rendom
                    wrote on 1 Aug 2017, 06:13 last edited by
                    #9

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

                    M 1 Reply Last reply 19 Oct 2017, 18:44
                    0
                    • R Rendom
                      1 Aug 2017, 06:13

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

                      M Offline
                      M Offline
                      mikelui
                      wrote on 19 Oct 2017, 18:44 last edited by
                      #10

                      @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=378523

                      The issue seems to intermittently pop back up for me, on ArchLinux

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved