diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/plugins/platforms/windows/qwindowstheme.cpp | 44 | ||||
| -rw-r--r-- | src/plugins/platforms/windows/qwindowstheme.h | 3 |
2 files changed, 28 insertions, 19 deletions
diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index f35d9a81025..64d459aee6b 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -95,6 +95,12 @@ static constexpr QColor getSysColor(winrt::Windows::UI::Color &&color) } #endif +static inline QColor getSysColor(int index) +{ + COLORREF cr = GetSysColor(index); + return QColor(GetRValue(cr), GetGValue(cr), GetBValue(cr)); +} + [[maybe_unused]] [[nodiscard]] static inline QColor qt_accentColor(AccentColorLevel level) { #if QT_CONFIG(cpp_winrt) @@ -108,18 +114,28 @@ static constexpr QColor getSysColor(winrt::Windows::UI::Color &&color) const QColor accentDarker = getSysColor(settings.GetColorValue(UIColorType::AccentDark2)); const QColor accentDarkest = getSysColor(settings.GetColorValue(UIColorType::AccentDark3)); #else - const QWinRegistryKey registry(HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\DWM)"); - if (!registry.isValid()) - return {}; - const QVariant value = registry.value(L"AccentColor"); - if (!value.isValid()) - return {}; - // The retrieved value is in the #AABBGGRR format, we need to - // convert it to the #AARRGGBB format which Qt expects. - const QColor abgr = QColor::fromRgba(qvariant_cast<DWORD>(value)); - if (!abgr.isValid()) + const QColor accent = []()->QColor { + // MS uses the aquatic contrast theme as an example in the URL below: + // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsyscolor#windows-1011-system-colors + if (QWindowsTheme::queryHighContrast()) + return getSysColor(COLOR_HIGHLIGHT); + const QWinRegistryKey registry(HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\DWM)"); + if (!registry.isValid()) + return {}; + const QVariant value = registry.value(L"AccentColor"); + if (!value.isValid()) + return {}; + // The retrieved value is in the #AABBGGRR format, we need to + // convert it to the #AARRGGBB format which Qt expects. + const QColor abgr = QColor::fromRgba(qvariant_cast<DWORD>(value)); + if (!abgr.isValid()) + return {}; + return QColor::fromRgb(abgr.blue(), abgr.green(), abgr.red(), abgr.alpha()); + + }(); + if (!accent.isValid()) return {}; - const QColor accent = QColor::fromRgb(abgr.blue(), abgr.green(), abgr.red(), abgr.alpha()); + const QColor accentLight = accent.lighter(120); const QColor accentLighter = accentLight.lighter(120); const QColor accentLightest = accentLighter.lighter(120); @@ -145,12 +161,6 @@ static constexpr QColor getSysColor(winrt::Windows::UI::Color &&color) } } -static inline QColor getSysColor(int index) -{ - COLORREF cr = GetSysColor(index); - return QColor(GetRValue(cr), GetGValue(cr), GetBValue(cr)); -} - // QTBUG-48823/Windows 10: SHGetFileInfo() (as called by item views on file system // models has been observed to trigger a WM_PAINT on the mainwindow. Suppress the // behavior by running it in a thread. diff --git a/src/plugins/platforms/windows/qwindowstheme.h b/src/plugins/platforms/windows/qwindowstheme.h index 63554d12887..c07f1a11695 100644 --- a/src/plugins/platforms/windows/qwindowstheme.h +++ b/src/plugins/platforms/windows/qwindowstheme.h @@ -64,7 +64,7 @@ public: static const char *name; static QPalette systemPalette(Qt::ColorScheme); - + static bool queryHighContrast(); private: void clearPalettes(); void refreshPalettes(); @@ -76,7 +76,6 @@ private: static Qt::ColorScheme queryColorScheme(); static Qt::ColorScheme effectiveColorScheme(); - static bool queryHighContrast(); static QWindowsTheme *m_instance; static inline Qt::ColorScheme s_colorScheme = Qt::ColorScheme::Unknown; |
