Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ApplicationWindow font not changed by QGuiApplication::setFont
Qt 6.12 LTS is out! See what's new in the release blog

ApplicationWindow font not changed by QGuiApplication::setFont

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
21 Posts 4 Posters 15.6k Views 4 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.
  • M Offline
    M Offline
    MaxL
    wrote on last edited by
    #11

    Well unfortunately same issue with Qt5.8

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MaxL
      wrote on last edited by
      #12

      Better workaround right now is to set the font of the QApplication and set it also to the ApplicationWindow.
      This way you have all qml elements using the same font. ( Set the font as a contextProperty so if you change it in cpp you won't have to change it in your ApplicationWindow )

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kmatheussen
        wrote on last edited by
        #13

        It works if you have a static UI but if you load dynamically some Widgets then they won't have the right font unless you set it each time you create a new one.

        Are you sure? It looks like the font set by using QApplication::setFont() is working after QApplication::exec() has started running.

        You should use #ifdef Q_OS_OSX .

        Yeah, but "FOR_MACOSX" is just a macro in my program. Not all source files are using Qt.

        For macOS version you can take a look at NSProcessInfo's operatingSystemVersion

        Unfortunately, I think, that function is only available in 10.10 and later.

        Better workaround right now is to set the font of the QApplication and set it also to the ApplicationWindow.

        Oh, so in addition to calling QApplication::setFont(), you can call qmainwindow->setFont(), and that's enough? Thanks, I'll try that.

        M 1 Reply Last reply
        0
        • K kmatheussen

          It works if you have a static UI but if you load dynamically some Widgets then they won't have the right font unless you set it each time you create a new one.

          Are you sure? It looks like the font set by using QApplication::setFont() is working after QApplication::exec() has started running.

          You should use #ifdef Q_OS_OSX .

          Yeah, but "FOR_MACOSX" is just a macro in my program. Not all source files are using Qt.

          For macOS version you can take a look at NSProcessInfo's operatingSystemVersion

          Unfortunately, I think, that function is only available in 10.10 and later.

          Better workaround right now is to set the font of the QApplication and set it also to the ApplicationWindow.

          Oh, so in addition to calling QApplication::setFont(), you can call qmainwindow->setFont(), and that's enough? Thanks, I'll try that.

          M Offline
          M Offline
          MaxL
          wrote on last edited by
          #14

          Are you sure? It looks like the font set by using QApplication::setFont() is working after QApplication::exec() has started running.

          Well yes it still work for components that do respect the setFont such as Text. But components like Button, they will not be with the right font and therefore you will have to set it.

          Unfortunately, I think, that function is only available in 10.10 and later.

          I forgot about QSysInfo. You should have everything you need in there.

          Oh, so in addition to calling QApplication::setFont(), you can call qmainwindow->setFont(), and that's enough? Thanks, I'll try that.

          Well in QML if I set the font to the ApplicationWindow then yes all elements that were not well handling the setFont are now using the right one.

          I found out what is the issue or at least pin pointed it.
          If I use QQuick.Controls 1.x, Button does have the font set by setFont however if I switch to QQuickView.Controls 2.0 then it is not using the right font.

          My guess is that I have to define a style that uses the font I want instead of using setFont ?

          1 Reply Last reply
          0
          • veryqtpersonV Offline
            veryqtpersonV Offline
            veryqtperson
            wrote on last edited by veryqtperson
            #15

            I don't remember the case exactly, but just setFont() didn't work for me as well. So I ended up with this crutch (which works fine):

            int id = QFontDatabase::addApplicationFont(":/fonts/TitilliumWeb-Regular.ttf");
            app.setFont(QFont(QFontDatabase::applicationFontFamilies(id).at(0)));
            
            1 Reply Last reply
            0
            • K Offline
              K Offline
              kmatheussen
              wrote on last edited by
              #16

              Just for the record, I don't use QQuick, so this is a broader problem.

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

                Sounds there's indeed something fishy going on.

                Can you create a minimal compilable example that shows the behaviour ?

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

                  @SGaist, will do, do you want me to send it to the bug report page ?
                  @veryqtperson , it is what I have done, my font is registered.

                  K 1 Reply Last reply
                  0
                  • M MaxL

                    @SGaist, will do, do you want me to send it to the bug report page ?
                    @veryqtperson , it is what I have done, my font is registered.

                    K Offline
                    K Offline
                    kmatheussen
                    wrote on last edited by
                    #19

                    @MaxL said in ApplicationWindow font not changed by QGuiApplication::setFont:

                    @SGaist, will do, do you want me to send it to the bug report page ?
                    @veryqtperson , it is what I have done, my font is registered.

                    Yes, I don't think QFontDatabase has anything to do with it. I don't have a Sierra computer in front of me right now, but I think this simple program could be enought to demonstrate the problem:

                    int main(int argc, char **argv){
                        QApplication app(argc,argv);
                        QString fontstring("Lato,10,-1,5,87,0,0,0,0,0"); // Change this string if you don't have this font on your computer.
                        QApplication::setFont(fontstring); 
                        QMessageBox msgBox;
                        msgBox.setText("This text is not printed using "+fontstring);
                        msgBox.exec();
                        return 0;
                    }
                    
                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      kmatheussen
                      wrote on last edited by kmatheussen
                      #20

                      Sorry, the program I posted in the previous message didn't trigger the bug. I also tried to copy various things from the initialization of the program (the one that did trigger the bug) into 'main' above, but without any luck.

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        MaxL
                        wrote on last edited by
                        #21

                        Hi guys,

                        You can find a small app that shows how the setFont is handle that you can download from my Google Drive

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