diff options
author | Andy Shaw <andy.shaw@qt.io> | 2020-04-22 13:56:38 +0200 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2020-04-24 10:10:55 +0200 |
commit | dddd197d42929149eafc5cb7754b7e6b323a4e97 (patch) | |
tree | 472336cee71d3e73e5f33a5d4669b208631df631 /src/widgets/kernel/qapplication.cpp | |
parent | 44e8c90ad4ae5a3d08651a61ac9f0937fb49d26b (diff) |
Deprecate QGuiApplication::fontChanged() signal
Rather than have a fontChanged() signal which can be connected to for
tracking when the application font has changed, then it is better to
use the event that is sent to all windows and the application itself.
That way it is easy for a window/widget or item that cares about the
change to the application font to catch it in the event() function.
[ChangeLog][QtGui][QGuiApplication] Deprecated fontChanged() signal in
favor of QEvent::ApplicationFontChanged.
Change-Id: Iae8e832238fc85e385a52305bc04f16e597454b0
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/kernel/qapplication.cpp')
-rw-r--r-- | src/widgets/kernel/qapplication.cpp | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 27af52e199..d0d2ab22ce 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -1356,26 +1356,20 @@ QFont QApplication::font(const char *className) void QApplication::setFont(const QFont &font, const char *className) { - bool all = false; FontHash *hash = app_fonts(); if (!className) { QGuiApplication::setFont(font); - if (hash && hash->size()) { - all = true; + if (hash && hash->size()) hash->clear(); - } } else if (hash) { hash->insert(className, font); } if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) { - // Send ApplicationFontChange to qApp itself, and to the widgets. QEvent e(QEvent::ApplicationFontChange); - QCoreApplication::sendEvent(QApplication::instance(), &e); - QWidgetList wids = QApplication::allWidgets(); for (QWidgetList::ConstIterator it = wids.constBegin(), cend = wids.constEnd(); it != cend; ++it) { QWidget *w = *it; - if (all || (!className && w->isWindow()) || w->inherits(className)) // matching class + if (!w->isWindow() && w->inherits(className)) // matching class sendEvent(w, &e); } @@ -1740,14 +1734,14 @@ bool QApplication::event(QEvent *e) #endif } - if(e->type() == QEvent::LanguageChange) { + if (e->type() == QEvent::LanguageChange || e->type() == QEvent::ApplicationFontChange) { // QGuiApplication::event does not account for the cases where // there is a top level widget without a window handle. So they // need to have the event posted here const QWidgetList list = topLevelWidgets(); for (auto *w : list) { if (!w->windowHandle() && (w->windowType() != Qt::Desktop)) - postEvent(w, new QEvent(QEvent::LanguageChange)); + postEvent(w, new QEvent(e->type())); } } |