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?

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.
  • C Offline
    C Offline
    CJha
    wrote on 21 Mar 2024, 07:48 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?

    P 1 Reply Last reply 21 Mar 2024, 12:30
    1
    • C CJha
      21 Mar 2024, 13:25

      @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?

      J Offline
      J Offline
      JonB
      wrote on 21 Mar 2024, 13:26 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).

      C 1 Reply Last reply 21 Mar 2024, 13:40
      1
      • C CJha
        21 Mar 2024, 07:48

        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?

        P Offline
        P Offline
        Pl45m4
        wrote on 21 Mar 2024, 12:30 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

        C 1 Reply Last reply 21 Mar 2024, 13:07
        0
        • P Pl45m4
          21 Mar 2024, 12:30

          @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

          C Offline
          C Offline
          CJha
          wrote on 21 Mar 2024, 13:07 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?

          J 1 Reply Last reply 21 Mar 2024, 13:17
          0
          • C CJha
            21 Mar 2024, 13:07

            @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?

            J Offline
            J Offline
            JonB
            wrote on 21 Mar 2024, 13:17 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!

            C 1 Reply Last reply 21 Mar 2024, 13:25
            1
            • J JonB
              21 Mar 2024, 13:17

              @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!

              C Offline
              C Offline
              CJha
              wrote on 21 Mar 2024, 13:25 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?

              J 1 Reply Last reply 21 Mar 2024, 13:26
              0
              • C CJha
                21 Mar 2024, 13:25

                @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?

                J Offline
                J Offline
                JonB
                wrote on 21 Mar 2024, 13:26 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).

                C 1 Reply Last reply 21 Mar 2024, 13:40
                1
                • J JonB
                  21 Mar 2024, 13:26

                  @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).

                  C Offline
                  C Offline
                  CJha
                  wrote on 21 Mar 2024, 13:40 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.

                  J 1 Reply Last reply 21 Mar 2024, 13:49
                  0
                  • C CJha
                    21 Mar 2024, 13:40

                    @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.

                    J Offline
                    J Offline
                    JonB
                    wrote on 21 Mar 2024, 13:49 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?

                    C 1 Reply Last reply 21 Mar 2024, 13:55
                    1
                    • J JonB
                      21 Mar 2024, 13:49

                      @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?

                      C Offline
                      C Offline
                      CJha
                      wrote on 21 Mar 2024, 13:55 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
                      • C CJha has marked this topic as solved on 21 Mar 2024, 13:55

                      2/9

                      21 Mar 2024, 12:30

                      topic:navigator.unread, 7
                      • Login

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