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. How to get the systems default sans serif monospace font?
Qt 6.11 is out! See what's new in the release blog

How to get the systems default sans serif monospace font?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 2.7k Views 3 Watching
  • 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.
  • G Offline
    G Offline
    GeraldBrandt
    wrote on last edited by
    #1

    Hi,

    Under Linux, when I create font and setFixedPitch on it, and get a nice monospaced font with no serifs. Under Windows I get Courier New. If I set styleHint() the font changes to non-fixed width.

    How can I get a fixed-width (monospaced) non-serif font under Windows (actually, all platforms).

    Gerald

    This doesn't work:

    QFont font("Mono", 12);
    font.setFixedPitch(true);
    font.setStyleHint(QFont::SansSerif);
    
    RokeJulianLockhartR 1 Reply Last reply
    1
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should add which version of Qt you are using on each platform.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GeraldBrandt
        wrote on last edited by
        #3

        Sorry, 5.14.1, I believe..

        I just told both Linux and Windows to load the Consolas font, and it works. Linux uses Deja Vu Sans Mono instead.

        Gerald

        1 Reply Last reply
        0
        • G GeraldBrandt

          Hi,

          Under Linux, when I create font and setFixedPitch on it, and get a nice monospaced font with no serifs. Under Windows I get Courier New. If I set styleHint() the font changes to non-fixed width.

          How can I get a fixed-width (monospaced) non-serif font under Windows (actually, all platforms).

          Gerald

          This doesn't work:

          QFont font("Mono", 12);
          font.setFixedPitch(true);
          font.setStyleHint(QFont::SansSerif);
          
          RokeJulianLockhartR Offline
          RokeJulianLockhartR Offline
          RokeJulianLockhart
          wrote on last edited by
          #4

          @GeraldBrandt, did you ever learn how to ascertain which font aliases correlate to which fonts on Windows? If not, I've recently asked https://webmasters.stackexchange.com/q/145196/122892, but that's solely half of the puzzle, so I'd like to know if possible.

          When using a forum, remember to tag the person you are responding to, in case they are not subscribed to the thread.

          C 1 Reply Last reply
          0
          • RokeJulianLockhartR RokeJulianLockhart

            @GeraldBrandt, did you ever learn how to ascertain which font aliases correlate to which fonts on Windows? If not, I've recently asked https://webmasters.stackexchange.com/q/145196/122892, but that's solely half of the puzzle, so I'd like to know if possible.

            C Offline
            C Offline
            ChrisW67
            wrote on last edited by ChrisW67
            #5

            @RokeJulianLockhart You should be able to create a QFont and then use QFontInfo to see what you actually got and whether it was an exact match or not.

            {
            QFont font("sans serif");
            QFontInfo info(font);
            qDebug() << font;
            qDebug() << info.exactMatch() << info.family() << info.pointSizeF();
            
            // QFont(sans serif,12,-1,5,50,0,0,0,0,0)
            // false "Noto Sans" 12
            }
            {
            QFont font("Noto Sans");
            QFontInfo info(font);
            qDebug() << font;
            qDebug() << info.exactMatch() << info.family() << info.pointSizeF();
            
            //QFont(Noto Sans,12,-1,5,50,0,0,0,0,0)
            //true "Noto Sans" 12 false
            }
            

            The aliases and their mappings vary from Windows version to version.
            You could look at Font-name and the registry key HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes

            RokeJulianLockhartR 1 Reply Last reply
            2
            • C ChrisW67

              @RokeJulianLockhart You should be able to create a QFont and then use QFontInfo to see what you actually got and whether it was an exact match or not.

              {
              QFont font("sans serif");
              QFontInfo info(font);
              qDebug() << font;
              qDebug() << info.exactMatch() << info.family() << info.pointSizeF();
              
              // QFont(sans serif,12,-1,5,50,0,0,0,0,0)
              // false "Noto Sans" 12
              }
              {
              QFont font("Noto Sans");
              QFontInfo info(font);
              qDebug() << font;
              qDebug() << info.exactMatch() << info.family() << info.pointSizeF();
              
              //QFont(Noto Sans,12,-1,5,50,0,0,0,0,0)
              //true "Noto Sans" 12 false
              }
              

              The aliases and their mappings vary from Windows version to version.
              You could look at Font-name and the registry key HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes

              RokeJulianLockhartR Offline
              RokeJulianLockhartR Offline
              RokeJulianLockhart
              wrote on last edited by RokeJulianLockhart
              #6

              @ChrisW67, that's brilliant. Thank you. I've found some useful corroberating information at https://superuser.com/a/1512700/904401.

              When using a forum, remember to tag the person you are responding to, in case they are not subscribed to the thread.

              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