From 35ee5b4eb7b1bde929ddb28dcd98e3c582006e13 Mon Sep 17 00:00:00 2001 From: Santhosh Kumar Date: Wed, 14 Jun 2023 10:12:35 +0200 Subject: [PATCH] Set color scheme after handling theme change in windows Setting color scheme before handling theme change provides incorrect palette color when user switches from light to dark or dark to light. This is visible when using Fusion style (or other style that supports dark mode) in Windows. The change has been made as part of patchset 787038bb1d282b4d6c5c040d8e902ccac9befb41. It also has to be noted that handling palette changes to make further changes to the palette (or the style sheet), is less likely than Handling the colorScheme change signal and in this sense, this patch set can also be considered as an improvement. This patchset reverts that change and updates color scheme after palette change in the application. [ChangeLog][QtGui][ColorScheme] Update colorScheme property after palette change. Fixes: QTBUG-112653 Change-Id: I71bc413c56663fefdf9fe5871bbb19b7e6c3d9ff Reviewed-by: Axel Spoerl (cherry picked from commit 39882a1354cb06d2b0b0a0d5b41a168041df0476) Reviewed-by: Qt Cherry-pick Bot --- src/gui/kernel/qguiapplication.cpp | 3 ++- src/gui/kernel/qguiapplication_p.h | 4 ++-- src/plugins/styles/windowsvista/qwindowsvistastyle.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 60e9e499264..9c09bc2d4ac 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2637,12 +2637,13 @@ void QGuiApplicationPrivate::processSafeAreaMarginsChangedEvent(QWindowSystemInt void QGuiApplicationPrivate::processThemeChanged(QWindowSystemInterfacePrivate::ThemeChangeEvent *tce) { - QStyleHintsPrivate::get(QGuiApplication::styleHints())->setColorScheme(colorScheme()); if (self) self->handleThemeChanged(); QIconPrivate::clearIconCache(); + QStyleHintsPrivate::get(QGuiApplication::styleHints())->setColorScheme(colorScheme()); + QEvent themeChangeEvent(QEvent::ThemeChange); const QWindowList windows = tce->window ? QWindowList{tce->window} : window_list; for (auto *window : windows) diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 14a81daed52..c96cbdd01f8 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -320,6 +320,8 @@ public: static void updatePalette(); + static Qt::ColorScheme colorScheme(); + protected: virtual void handleThemeChanged(); @@ -336,8 +338,6 @@ private: friend class QDragManager; - static Qt::ColorScheme colorScheme(); - static QGuiApplicationPrivate *self; static int m_fakeMouseSourcePointId; #ifdef Q_OS_WIN diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp index 184378e4e11..dc6cd188e8c 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp @@ -4808,7 +4808,7 @@ void QWindowsVistaStyle::polish(QPalette &pal) { Q_D(QWindowsVistaStyle); - if (qApp->styleHints()->colorScheme() == Qt::ColorScheme::Dark) { + if (QGuiApplicationPrivate::colorScheme() == Qt::ColorScheme::Dark) { // System runs in dark mode, but the Vista style cannot use a dark palette. // Overwrite with the light system palette. using QWindowsApplication = QNativeInterface::Private::QWindowsApplication;