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. Where does Qt get the default application font?
Forum Updated to NodeBB v4.3 + New Features

Where does Qt get the default application font?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 6 Posters 40.5k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1

    I am working on an application and I am having some issues with the style of it. I am on a Linux system, running Red Hat Enterprise Linux 7.4 and KDE Plasma. In Plasma, I have checked my font settings and the standard there is "Sans Serif 10". All other fonts are either smaller or the same size.

    However, when I do this:

    qDebug() << QApplication::font();
    

    I get this result:

    QFont( "Sans Serif,12,-1,5,50,0,0,0,0,0" )
    

    which makes me wonder, where Qt gets its default font from and how I can influence it. The Qt documentation states pretty clearly not to use the QApplication::setFont() method together with style sheets. Where I am trying to get to is to set relative font sizes with the stylesheet and allow the user to select his base size from which the relative sizes are then derived. Is there a way to get there?

    Taz742T 1 Reply Last reply
    5
    • ? A Former User

      I am working on an application and I am having some issues with the style of it. I am on a Linux system, running Red Hat Enterprise Linux 7.4 and KDE Plasma. In Plasma, I have checked my font settings and the standard there is "Sans Serif 10". All other fonts are either smaller or the same size.

      However, when I do this:

      qDebug() << QApplication::font();
      

      I get this result:

      QFont( "Sans Serif,12,-1,5,50,0,0,0,0,0" )
      

      which makes me wonder, where Qt gets its default font from and how I can influence it. The Qt documentation states pretty clearly not to use the QApplication::setFont() method together with style sheets. Where I am trying to get to is to set relative font sizes with the stylesheet and allow the user to select his base size from which the relative sizes are then derived. Is there a way to get there?

      Taz742T Offline
      Taz742T Offline
      Taz742
      wrote on last edited by Taz742
      #2

      @tobiSF
      I dont have answer on your question Where does Qt get the default application font?, but i advice for you one way for your question: Where I am trying to get to is to set relative font sizes with the stylesheet and allow the user to select his base size from which the relative sizes are then derived. Is there a way to get there?

      • create a one (dialog or widget) form named by Configuration. Create a your design where you will have a list of the fonts that you are giving customers.
      • Also give them the opportunity to choose the size of the font.

      The good thing is that we can change the font when application is running.

      It is a example, how to install the font for our application:

          int id = QFontDatabase::addApplicationFont(":/SMSicons/segoeui_0.ttf");
          QString family = QFontDatabase::applicationFontFamilies(id).at(0);
          QFont _font(family, 8);
          qApp->setFont(_font);
      

      Do what you want.

      ? RokeJulianLockhartR 2 Replies Last reply
      1
      • Taz742T Taz742

        @tobiSF
        I dont have answer on your question Where does Qt get the default application font?, but i advice for you one way for your question: Where I am trying to get to is to set relative font sizes with the stylesheet and allow the user to select his base size from which the relative sizes are then derived. Is there a way to get there?

        • create a one (dialog or widget) form named by Configuration. Create a your design where you will have a list of the fonts that you are giving customers.
        • Also give them the opportunity to choose the size of the font.

        The good thing is that we can change the font when application is running.

        It is a example, how to install the font for our application:

            int id = QFontDatabase::addApplicationFont(":/SMSicons/segoeui_0.ttf");
            QString family = QFontDatabase::applicationFontFamilies(id).at(0);
            QFont _font(family, 8);
            qApp->setFont(_font);
        
        ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        @Taz742 thanks for your response.

        I do know how to set the application font, and I do have a QFontDialog in my application right now to do that. However, Qt documentation states not to use qApp->setFont() in connection with Stylesheets.

        Since stylesheets cannot deal with relative font-size anyway, I am focusing on letting the user chose his base font and the stylesheet simply add emphasis (bold, italic,...) where required. However, my concern is about the startup, when the user does not select a font. I believe it is best practice to use the default system font, but it doesn't look like my Qt application is pulling what I think should be the default system font but something else instead. And I wonder, where this 'something else' might come from so I can handle it.

        JonBJ 1 Reply Last reply
        0
        • ? A Former User

          @Taz742 thanks for your response.

          I do know how to set the application font, and I do have a QFontDialog in my application right now to do that. However, Qt documentation states not to use qApp->setFont() in connection with Stylesheets.

          Since stylesheets cannot deal with relative font-size anyway, I am focusing on letting the user chose his base font and the stylesheet simply add emphasis (bold, italic,...) where required. However, my concern is about the startup, when the user does not select a font. I believe it is best practice to use the default system font, but it doesn't look like my Qt application is pulling what I think should be the default system font but something else instead. And I wonder, where this 'something else' might come from so I can handle it.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @tobiSF
          https://unix.stackexchange.com/questions/116595/how-do-i-set-default-font-for-all-qt5-applications
          https://stackoverflow.com/questions/11011238/how-do-you-get-system-default-font-settings-in-qt

          ?

          It would also be nice if one of the "experts" in this forum answered this thread, as it seems pretty difficult to understand where Qt (5, at least) actually does pick up its default fonts from under various OSes....

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            IIRC, on Linux, it comes from FontConfig.

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

            JonBJ 1 Reply Last reply
            1
            • SGaistS SGaist

              Hi,

              IIRC, on Linux, it comes from FontConfig.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @SGaist
              And under Windows it comes from .... magic ??

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                @SGaist LOL, that's how it looks like

                raven-worxR 1 Reply Last reply
                0
                • ? A Former User

                  @SGaist LOL, that's how it looks like

                  raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by raven-worx
                  #8

                  @tobiSF
                  From the QPA plugin
                  From there on via QWindowsFontDatabase -> etc...

                  Also see the QApplication::font() methods for gathering the different fonts for different widget types.

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  3
                  • Taz742T Taz742

                    @tobiSF
                    I dont have answer on your question Where does Qt get the default application font?, but i advice for you one way for your question: Where I am trying to get to is to set relative font sizes with the stylesheet and allow the user to select his base size from which the relative sizes are then derived. Is there a way to get there?

                    • create a one (dialog or widget) form named by Configuration. Create a your design where you will have a list of the fonts that you are giving customers.
                    • Also give them the opportunity to choose the size of the font.

                    The good thing is that we can change the font when application is running.

                    It is a example, how to install the font for our application:

                        int id = QFontDatabase::addApplicationFont(":/SMSicons/segoeui_0.ttf");
                        QString family = QFontDatabase::applicationFontFamilies(id).at(0);
                        QFont _font(family, 8);
                        qApp->setFont(_font);
                    
                    RokeJulianLockhartR Offline
                    RokeJulianLockhartR Offline
                    RokeJulianLockhart
                    wrote on last edited by RokeJulianLockhart
                    #9
                    Typefaces

                    QFontDatabase

                    @Taz742, it looks like the answer to this question is QFontDatabase::SystemFont:

                    enum QFontDatabase::SystemFont
                    Constant Value Description
                    QFontDatabase::GeneralFont 0 The default system font.
                    QFontDatabase::FixedFont 1 The fixed font that the system recommends.
                    QFontDatabase::TitleFont 2 The system standard font for titles.
                    QFontDatabase::SmallestReadableFont 3 The smallest readable system font.
                    Sizes

                    Does anyone know of anything similar for font sizes? I realise that warrants another question, but...

                    The undermentioned appear correct:

                    1. QFontDatabase::standardSizes()
                    2. QFontDatabase::smoothSizes()
                    3. QFontDatabase::pointSizes()

                    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