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. Qt 6 fontChanged signal?
QtWS25 Last Chance

Qt 6 fontChanged signal?

Scheduled Pinned Locked Moved Solved General and Desktop
font changeqapplicationqt 6
9 Posts 3 Posters 894 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.
  • CJhaC Offline
    CJhaC Offline
    CJha
    wrote on last edited by
    #1

    Hi, I have a few widgets which react to application font changes (their font sizes are a bit larger than the application font). I am using Qt 6.5 and since Qt 6 the fontChanged(const QFont &font) has been deprecated and it is suggested to handle QEvent::ApplicationFontChange event. However, I am unable to see this event being called in either QWidget::changeEvent(QEvent *event) or in the event filter. How can I get a signal/event notification in Qt 6 and above when the application font changes?

    Pl45m4P 1 Reply Last reply
    1
    • CJhaC CJha

      @JonB I did and it works, if I subclass QApplication I can see the QEvent::ApplicationFontChange in overridden bool event(QEvent *e) function. Is it the only way to detect this event?

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

      @CJha
      That I don't know, and I don't use Qt6, but at least you know where you are now for sure, just in case! :)

      I don't know whether ApplicationFontChange is supposed to trigger an event to every widget. If you have the source you might look at that while you await a better response. 3 years ago https://stackoverflow.com/q/65935188/489865

      I noticed there is also ApplicationFontChange, which is promising, however that event is not delivered to my custom widget (I verified using an event listener). Looking at the Qt code, the code responsible for propagating the ApplicationFontChange event will only deliver this event to a few select widgets (the main window for example).

      CJhaC 1 Reply Last reply
      1
      • CJhaC CJha

        Hi, I have a few widgets which react to application font changes (their font sizes are a bit larger than the application font). I am using Qt 6.5 and since Qt 6 the fontChanged(const QFont &font) has been deprecated and it is suggested to handle QEvent::ApplicationFontChange event. However, I am unable to see this event being called in either QWidget::changeEvent(QEvent *event) or in the event filter. How can I get a signal/event notification in Qt 6 and above when the application font changes?

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by Pl45m4
        #2

        @CJha

        As you can read here, QEvent::ApplicationFontChange is not included in QWidget::changeEvent.
        Try QWidget::event or QGuiApplication::event instead

        Btw:

        QEvent::FontChange ≠ QEvent::ApplicationFontChange


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        CJhaC 1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          @CJha

          As you can read here, QEvent::ApplicationFontChange is not included in QWidget::changeEvent.
          Try QWidget::event or QGuiApplication::event instead

          Btw:

          QEvent::FontChange ≠ QEvent::ApplicationFontChange

          CJhaC Offline
          CJhaC Offline
          CJha
          wrote on last edited by
          #3

          @Pl45m4 said in Qt 6 fontChanged signal?:

          QEvent::FontChange ≠ QEvent::ApplicationFontChange

          That I know.

          QWidget::event is not receiving the QEvent::ApplicationFontChange, QGuiApplication::event might, but I do not want to subclass just to emit the fontChanged signal from it on my own. If the QEvent::ApplicationFontChange exists, there must be a way to detect it in any other class other than QApplication otherwise what is the use of such an event?

          JonBJ 1 Reply Last reply
          0
          • CJhaC CJha

            @Pl45m4 said in Qt 6 fontChanged signal?:

            QEvent::FontChange ≠ QEvent::ApplicationFontChange

            That I know.

            QWidget::event is not receiving the QEvent::ApplicationFontChange, QGuiApplication::event might, but I do not want to subclass just to emit the fontChanged signal from it on my own. If the QEvent::ApplicationFontChange exists, there must be a way to detect it in any other class other than QApplication otherwise what is the use of such an event?

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

            @CJha
            But for the sake of a few minutes you might at least try subclassing your app just to verify that it does receive ApplicationFontChange at all? You could be whistling in the wind if that event is never being issued at all!

            CJhaC 1 Reply Last reply
            1
            • JonBJ JonB

              @CJha
              But for the sake of a few minutes you might at least try subclassing your app just to verify that it does receive ApplicationFontChange at all? You could be whistling in the wind if that event is never being issued at all!

              CJhaC Offline
              CJhaC Offline
              CJha
              wrote on last edited by
              #5

              @JonB I did and it works, if I subclass QApplication I can see the QEvent::ApplicationFontChange in overridden bool event(QEvent *e) function. Is it the only way to detect this event?

              JonBJ 1 Reply Last reply
              0
              • CJhaC CJha

                @JonB I did and it works, if I subclass QApplication I can see the QEvent::ApplicationFontChange in overridden bool event(QEvent *e) function. Is it the only way to detect this event?

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

                @CJha
                That I don't know, and I don't use Qt6, but at least you know where you are now for sure, just in case! :)

                I don't know whether ApplicationFontChange is supposed to trigger an event to every widget. If you have the source you might look at that while you await a better response. 3 years ago https://stackoverflow.com/q/65935188/489865

                I noticed there is also ApplicationFontChange, which is promising, however that event is not delivered to my custom widget (I verified using an event listener). Looking at the Qt code, the code responsible for propagating the ApplicationFontChange event will only deliver this event to a few select widgets (the main window for example).

                CJhaC 1 Reply Last reply
                1
                • JonBJ JonB

                  @CJha
                  That I don't know, and I don't use Qt6, but at least you know where you are now for sure, just in case! :)

                  I don't know whether ApplicationFontChange is supposed to trigger an event to every widget. If you have the source you might look at that while you await a better response. 3 years ago https://stackoverflow.com/q/65935188/489865

                  I noticed there is also ApplicationFontChange, which is promising, however that event is not delivered to my custom widget (I verified using an event listener). Looking at the Qt code, the code responsible for propagating the ApplicationFontChange event will only deliver this event to a few select widgets (the main window for example).

                  CJhaC Offline
                  CJhaC Offline
                  CJha
                  wrote on last edited by
                  #7

                  @JonB Thanks! As mentioned in the SO post that you linked, I can see the QEvent::ApplicationFontChange in the MainWindow bool event(QEvent* e) override; function. This is a stupid design change because the MainWindow holds other widgets and those do not have access to the MainWindow class object, so emitting the signal from MainWindow and receiving it in another widget is going to be a problem. But I guess I can figure out some way around it.

                  Honestly, I do not understand why remove the fontChanged signal from QApplication in Qt 6, in my opinion, is it like taking a step backwards.

                  JonBJ 1 Reply Last reply
                  0
                  • CJhaC CJha

                    @JonB Thanks! As mentioned in the SO post that you linked, I can see the QEvent::ApplicationFontChange in the MainWindow bool event(QEvent* e) override; function. This is a stupid design change because the MainWindow holds other widgets and those do not have access to the MainWindow class object, so emitting the signal from MainWindow and receiving it in another widget is going to be a problem. But I guess I can figure out some way around it.

                    Honestly, I do not understand why remove the fontChanged signal from QApplication in Qt 6, in my opinion, is it like taking a step backwards.

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

                    @CJha
                    Like I said, I don't have Qt6 or source. But maybe have a look at https://www.opencoverage.net/qtbase/QtBase_html/source_116.html I came across.

                    1675	    if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) {
                    0
                    1676	        // Send ApplicationFontChange to qApp itself, and to the widgets.	-
                    1677	        QEvent e(QEvent::ApplicationFontChange);	-
                    1678	        QApplication::sendEvent(QApplication::instance(), &e);	-
                    1679		-
                    1680	        QWidgetList wids = QApplication::allWidgets();	-
                    1681	        for (QWidgetList::ConstIterator it = wids.constBegin(), cend = wids.constEnd(); it != cend; ++it) {
                    0
                    1682	            QWidget *w = *it;	-
                    1683	            if (all || (!className && w->isWindow()) || w->inherits(className)) // matching class
                    0
                    1684	                sendEvent(w, &e);
                    0
                    1685	        }
                    

                    Looks like something used to iterate QApplication::allWidgets(); propagating an event? Or, if this is still the code, maybe your widget does not pass if (all || (!className && w->isWindow()) || w->inherits(className)? If that is the code that was, maybe you want to do something similar for your case?

                    CJhaC 1 Reply Last reply
                    1
                    • JonBJ JonB

                      @CJha
                      Like I said, I don't have Qt6 or source. But maybe have a look at https://www.opencoverage.net/qtbase/QtBase_html/source_116.html I came across.

                      1675	    if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) {
                      0
                      1676	        // Send ApplicationFontChange to qApp itself, and to the widgets.	-
                      1677	        QEvent e(QEvent::ApplicationFontChange);	-
                      1678	        QApplication::sendEvent(QApplication::instance(), &e);	-
                      1679		-
                      1680	        QWidgetList wids = QApplication::allWidgets();	-
                      1681	        for (QWidgetList::ConstIterator it = wids.constBegin(), cend = wids.constEnd(); it != cend; ++it) {
                      0
                      1682	            QWidget *w = *it;	-
                      1683	            if (all || (!className && w->isWindow()) || w->inherits(className)) // matching class
                      0
                      1684	                sendEvent(w, &e);
                      0
                      1685	        }
                      

                      Looks like something used to iterate QApplication::allWidgets(); propagating an event? Or, if this is still the code, maybe your widget does not pass if (all || (!className && w->isWindow()) || w->inherits(className)? If that is the code that was, maybe you want to do something similar for your case?

                      CJhaC Offline
                      CJhaC Offline
                      CJha
                      wrote on last edited by
                      #9

                      @JonB Yeah, I could do something similar, iterate over all widgets and pass on the event. Thanks, I will try this method in the final application.

                      1 Reply Last reply
                      0
                      • CJhaC CJha has marked this topic as solved on

                      • Login

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