Emit paletteChanged and send ApplicationPaletteChange on theme change
Fixes: QTBUG-72575 Change-Id: I407e081295a456a7bdd36de91ca5bbf74bba6078 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
78b422c341
commit
98552a84ce
@ -3983,6 +3983,9 @@ void QGuiApplicationPrivate::notifyThemeChanged()
|
||||
!QCoreApplication::testAttribute(Qt::AA_SetPalette)) {
|
||||
clearPalette();
|
||||
initPalette();
|
||||
emit qGuiApp->paletteChanged(*app_pal);
|
||||
if (is_app_running && !is_app_closing)
|
||||
sendApplicationPaletteChange();
|
||||
}
|
||||
if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) {
|
||||
QMutexLocker locker(&applicationFontMutex);
|
||||
@ -3991,6 +3994,15 @@ void QGuiApplicationPrivate::notifyThemeChanged()
|
||||
}
|
||||
}
|
||||
|
||||
void QGuiApplicationPrivate::sendApplicationPaletteChange(bool toAllWidgets, const char *className)
|
||||
{
|
||||
Q_UNUSED(toAllWidgets)
|
||||
Q_UNUSED(className)
|
||||
|
||||
QEvent event(QEvent::ApplicationPaletteChange);
|
||||
QGuiApplication::sendEvent(QGuiApplication::instance(), &event);
|
||||
}
|
||||
|
||||
#if QT_CONFIG(draganddrop)
|
||||
void QGuiApplicationPrivate::notifyDragStarted(const QDrag *drag)
|
||||
{
|
||||
|
@ -313,6 +313,7 @@ public:
|
||||
|
||||
protected:
|
||||
virtual void notifyThemeChanged();
|
||||
virtual void sendApplicationPaletteChange(bool toAllWidgets = false, const char *className = nullptr);
|
||||
bool tryCloseRemainingWindows(QWindowList processedWindows);
|
||||
#if QT_CONFIG(draganddrop)
|
||||
virtual void notifyDragStarted(const QDrag *);
|
||||
|
@ -1420,24 +1420,7 @@ void QApplicationPrivate::setPalette_helper(const QPalette &palette, const char*
|
||||
|
||||
if (QApplicationPrivate::is_app_running && !QApplicationPrivate::is_app_closing) {
|
||||
// Send ApplicationPaletteChange to qApp itself, and to the widgets.
|
||||
QEvent e(QEvent::ApplicationPaletteChange);
|
||||
QApplication::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
|
||||
QApplication::sendEvent(w, &e);
|
||||
}
|
||||
|
||||
// Send to all scenes as well.
|
||||
#if QT_CONFIG(graphicsview)
|
||||
QList<QGraphicsScene *> &scenes = qApp->d_func()->scene_list;
|
||||
for (QList<QGraphicsScene *>::ConstIterator it = scenes.constBegin();
|
||||
it != scenes.constEnd(); ++it) {
|
||||
QApplication::sendEvent(*it, &e);
|
||||
}
|
||||
#endif // QT_CONFIG(graphicsview)
|
||||
qApp->d_func()->sendApplicationPaletteChange(all, className);
|
||||
}
|
||||
if (!className && (!QApplicationPrivate::sys_pal || !palette.isCopyOf(*QApplicationPrivate::sys_pal))) {
|
||||
if (!QApplicationPrivate::set_pal)
|
||||
@ -4508,6 +4491,23 @@ void QApplicationPrivate::notifyThemeChanged()
|
||||
qt_init_tooltip_palette();
|
||||
}
|
||||
|
||||
void QApplicationPrivate::sendApplicationPaletteChange(bool toAllWidgets, const char *className)
|
||||
{
|
||||
QGuiApplicationPrivate::sendApplicationPaletteChange();
|
||||
|
||||
QEvent event(QEvent::ApplicationPaletteChange);
|
||||
const QWidgetList widgets = QApplication::allWidgets();
|
||||
for (auto widget : widgets) {
|
||||
if (toAllWidgets || (!className && widget->isWindow()) || (className && widget->inherits(className)))
|
||||
QApplication::sendEvent(widget, &event);
|
||||
}
|
||||
|
||||
#if QT_CONFIG(graphicsview)
|
||||
for (auto scene : qAsConst(scene_list))
|
||||
QApplication::sendEvent(scene, &event);
|
||||
#endif // QT_CONFIG(graphicsview)
|
||||
}
|
||||
|
||||
#if QT_CONFIG(draganddrop)
|
||||
void QApplicationPrivate::notifyDragStarted(const QDrag *drag)
|
||||
{
|
||||
|
@ -177,6 +177,9 @@ public:
|
||||
|
||||
protected:
|
||||
void notifyThemeChanged() override;
|
||||
void sendApplicationPaletteChange(bool toAllWidgets = false,
|
||||
const char *className = nullptr) override;
|
||||
|
||||
#if QT_CONFIG(draganddrop)
|
||||
void notifyDragStarted(const QDrag *) override;
|
||||
#endif // QT_CONFIG(draganddrop)
|
||||
|
Loading…
Reference in New Issue
Block a user