Qt 6 fontChanged signal?
-
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 handleQEvent::ApplicationFontChange
event. However, I am unable to see this event being called in eitherQWidget::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? -
@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/489865I 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 theApplicationFontChange
event will only deliver this event to a few select widgets (the main window for example). -
@Pl45m4 said in Qt 6 fontChanged signal?:
QEvent::FontChange ≠ QEvent::ApplicationFontChange
That I know.
QWidget::event
is not receiving theQEvent::ApplicationFontChange
,QGuiApplication::event
might, but I do not want to subclass just to emit the fontChanged signal from it on my own. If theQEvent::ApplicationFontChange
exists, there must be a way to detect it in any other class other thanQApplication
otherwise what is the use of such an event? -
@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/489865I 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 theApplicationFontChange
event will only deliver this event to a few select widgets (the main window for example). -
@JonB Thanks! As mentioned in the SO post that you linked, I can see the
QEvent::ApplicationFontChange
in the MainWindowbool 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. -
@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 passif (all || (!className && w->isWindow()) || w->inherits(className)
? If that is the code that was, maybe you want to do something similar for your case? -