Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Distributing fonts
Forum Update on Monday, May 27th 2025

Distributing fonts

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 4 Posters 2.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
    maxwell31
    wrote on last edited by
    #1

    Hi,

    I have an application for which I want to use the material style. The material style uses the Roboto font by google, but it needs to be installed on the system. How can I make sure, that the font is available on a system? Use the Qt-Installer framework and install the fonts (if this is even possible)? Or can I tell Qt to look for the fonts in a certain directory relative to the executable? If I simply put them into my resource file, e.g. the Buttons in Material style don't use the correct font (e.g. fall back to Noto which is installed on my linux machine)

    T 1 Reply Last reply
    0
    • M maxwell31

      Hi,

      I have an application for which I want to use the material style. The material style uses the Roboto font by google, but it needs to be installed on the system. How can I make sure, that the font is available on a system? Use the Qt-Installer framework and install the fonts (if this is even possible)? Or can I tell Qt to look for the fonts in a certain directory relative to the executable? If I simply put them into my resource file, e.g. the Buttons in Material style don't use the correct font (e.g. fall back to Noto which is installed on my linux machine)

      T Offline
      T Offline
      Tom_H
      wrote on last edited by
      #2

      @maxwell31 You have to add it to the font database. Then you can set the default application font with QGuiApplication::setFont.

      QFontDatabase fdb;
      fdb.addApplicationFont(":/res/fonts/myfont.ttf");
      
      1 Reply Last reply
      1
      • GrecKoG Offline
        GrecKoG Offline
        GrecKo
        Qt Champions 2018
        wrote on last edited by
        #3

        Or with a FontLoader in QML.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxwell31
          wrote on last edited by
          #4

          Adding it to the Font database and using "QGuiApplication::setFont" is working. However, something I wonder: How can I find out the name under which the font is available? Doing this

          QFontDatabase::addApplicationFont("qrc:/resources/Roboto-Regular.ttf");
          QFontDatabase::addApplicationFont("qrc:/resources/Roboto-Medium.ttf");
          QFontDatabase::addApplicationFont("qrc:/resources/Roboto-Light.ttf");
          QFontDatabase a;
          qDebug()<<a.families();
          

          does not show the Roboto fonts in the output.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maxwell31
            wrote on last edited by
            #5

            Ok, the error was that I have to do

            QFontDatabase::addApplicationFont(":/resources/Roboto-Regular.ttf");
            

            instead of qrc:. Actually I don't understand the difference between qrc and :

            raven-worxR 1 Reply Last reply
            0
            • M maxwell31

              Ok, the error was that I have to do

              QFontDatabase::addApplicationFont(":/resources/Roboto-Regular.ttf");
              

              instead of qrc:. Actually I don't understand the difference between qrc and :

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

              @maxwell31 said in Distributing fonts:

              instead of qrc:. Actually I don't understand the difference between qrc and :

              qrc:/ is a url format, wheras :/ is a filepath format

              --- 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
              2
              • M Offline
                M Offline
                maxwell31
                wrote on last edited by
                #7

                and urls don't work for the addApplicationFont?

                raven-worxR 1 Reply Last reply
                0
                • M maxwell31

                  and urls don't work for the addApplicationFont?

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

                  @maxwell31
                  urls are expected when the parameter type is also QUrl (at least mostly this is the case)
                  But if the parameter is of the type QString or named fileName you can assume it expects a file path.

                  --- 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
                  2
                  • M Offline
                    M Offline
                    maxwell31
                    wrote on last edited by
                    #9

                    Thanks. So here it expects a fileName, and if the file is in the resources, it should start with :/, alright.

                    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