From 2ced94b4100c03c5feb7d5b1c0006c9fc451e944 Mon Sep 17 00:00:00 2001 From: Wladimir Leuschner Date: Tue, 30 Jul 2024 14:36:13 +0200 Subject: [PATCH] WindowsQPA: Respect ENV and cmdline darkmode overrides Currently the commandline and environment parameters (windows:darkmode) for setting the darkmode handling are ignored when the application starts. This patch adds a condition to QWindowsTheme::effectiveColorScheme that checks whether darkmode handling was explicitly overridden and initializes in the constructor the m_colorScheme with the result of passing Qt::ColorScheme::Unknown toeffectiveColorScheme. Fixes: QTBUG-127135 Pick-to: 6.8 Change-Id: I365d26c66fdb3a754832cb7c579aeebecab093fd Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowstheme.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index 7806bec287d..a3c16b27271 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -483,7 +483,8 @@ QWindowsTheme *QWindowsTheme::m_instance = nullptr; QWindowsTheme::QWindowsTheme() { m_instance = this; - s_colorScheme = QWindowsTheme::queryColorScheme(); + s_colorScheme = Qt::ColorScheme::Unknown; + s_colorScheme = QWindowsTheme::effectiveColorScheme(); std::fill(m_fonts, m_fonts + NFonts, nullptr); std::fill(m_palettes, m_palettes + NPalettes, nullptr); refresh(); @@ -578,12 +579,15 @@ Qt::ColorScheme QWindowsTheme::colorScheme() const Qt::ColorScheme QWindowsTheme::effectiveColorScheme() { + auto integration = QWindowsIntegration::instance(); if (queryHighContrast()) return Qt::ColorScheme::Unknown; if (s_colorSchemeOverride != Qt::ColorScheme::Unknown) return s_colorSchemeOverride; if (s_colorScheme != Qt::ColorScheme::Unknown) return s_colorScheme; + if (!integration->darkModeHandling().testFlag(QWindowsApplication::DarkModeStyle)) + return Qt::ColorScheme::Light; return queryColorScheme(); }