From 0dab50a12408be68d782930bd46a9d3eba1d7d04 Mon Sep 17 00:00:00 2001 From: Piotr Wiercinski Date: Mon, 24 Mar 2025 17:09:49 +0100 Subject: [PATCH] gtk3theme: Flush PlatformTheme palette on ColorScheme change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit System color palette only takes the ColorScheme (Bright/Dark) into account during creation, which results in static color palette which does not reflect changes requested by `updateColorScheme`. Reinitialize the platform system color palette when ColorScheme is changed. Change-Id: I3f8f77a5990bda0f2db744f6ee8c6b392dfe8a84 Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qplatformtheme.cpp | 17 ++++++++++++++++- src/plugins/platformthemes/gtk3/qgtk3theme.cpp | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index 26cb075ca8d..d2a1625bf71 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -376,7 +376,8 @@ QPlatformThemePrivate::QPlatformThemePrivate() QPlatformThemePrivate::~QPlatformThemePrivate() { - delete systemPalette; + if (systemPalette) + delete systemPalette; } Q_GUI_EXPORT QPalette qt_fusionPalette() @@ -476,8 +477,22 @@ Qt::ColorScheme QPlatformTheme::colorScheme() const void QPlatformTheme::requestColorScheme(Qt::ColorScheme scheme) { Q_UNUSED(scheme); + Q_D(QPlatformTheme); + if (d->systemPalette) { + delete d->systemPalette; + d->systemPalette = nullptr; + } } +/*! + \internal + \brief Return a color palette for type \a type. + + When relying on system color palette keep in mind that it is + lazily initialized and cached. If it needs to be updated + (i.e. due to ColorScheme changes), it's up to the caller + to take care of it. See \c requestColorScheme. +*/ const QPalette *QPlatformTheme::palette(Palette type) const { Q_D(const QPlatformTheme); diff --git a/src/plugins/platformthemes/gtk3/qgtk3theme.cpp b/src/plugins/platformthemes/gtk3/qgtk3theme.cpp index ec54872347e..25decb235b7 100644 --- a/src/plugins/platformthemes/gtk3/qgtk3theme.cpp +++ b/src/plugins/platformthemes/gtk3/qgtk3theme.cpp @@ -165,6 +165,7 @@ void QGtk3Theme::requestColorScheme(Qt::ColorScheme scheme) return; qCDebug(lcQGtk3Interface) << scheme << "has been requested. Theme supports color scheme:" << m_storage->colorScheme(); + QPlatformTheme::requestColorScheme(scheme); m_requestedColorScheme = scheme; m_storage->handleThemeChange(); }