diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-12-07 17:37:09 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-12-08 17:56:48 +0100 |
commit | a2518b4140ed88a674bf4a4fcf4576e35c698bb9 (patch) | |
tree | 2efe09a5f39ebef0298ca8fb171dc2c8c83f21b4 /src/plugins/platforms/windows/qwindowstheme.cpp | |
parent | c62c2aac752c6b63d5afd2f7a10dd9f43c99ae7b (diff) |
Overwrite dark system palette in Vista style
The Vista style uses system assets for controls, and those are never
dark. Because of that we cannot support dark appearance with that style,
and applications using the Vista style should always use the light
system palette. Override QStyle::polish(QPalette &) in the vista style
to do that.
To make that palette available, move the code reading the light palette
into QWindowsApplication, and call that method from both the platform
theme (if the system is running in light mode) and from the Vista style
(only if the system is running in dark mode).
If the system is dark mode and another style is used (e.g. Fusion, which
works well with a dark palette), then the palette returned by the
platform theme gets used without any modifications.
This requires duplicating some small inline helper functions in
QWindowsTheme and QWindowsApplication. We can clean this up once the
implementation is complete for both Qt Widgets and Qt Quick.
Change-Id: Ia13f59a2d8414642603f9708926718daf9e8954d
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io>
Diffstat (limited to 'src/plugins/platforms/windows/qwindowstheme.cpp')
-rw-r--r-- | src/plugins/platforms/windows/qwindowstheme.cpp | 54 |
1 files changed, 5 insertions, 49 deletions
diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index 8e931b1ed8..b9d02a4374 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -63,11 +63,6 @@ QT_BEGIN_NAMESPACE using namespace Qt::StringLiterals; -static inline QColor COLORREFToQColor(COLORREF cr) -{ - return QColor(GetRValue(cr), GetGValue(cr), GetBValue(cr)); -} - static inline bool booleanSystemParametersInfo(UINT what, bool defaultValue) { BOOL result; @@ -93,7 +88,8 @@ static inline QColor mixColors(const QColor &c1, const QColor &c2) static inline QColor getSysColor(int index) { - return COLORREFToQColor(GetSysColor(index)); + COLORREF cr = GetSysColor(index); + return QColor(GetRValue(cr), GetGValue(cr), GetBValue(cr)); } #if QT_CONFIG(cpp_winrt) @@ -238,49 +234,9 @@ static QColor placeHolderColor(QColor textColor) */ static void populateLightSystemBasePalette(QPalette &result) { - QColor background = getSysColor(COLOR_BTNFACE); - QColor textColor = getSysColor(COLOR_WINDOWTEXT); - QColor accent = getSysColor(COLOR_HIGHLIGHT); - -#if QT_CONFIG(cpp_winrt) - if (QWindowsIntegration::instance()->darkModeHandling().testFlag(QWindowsApplication::DarkModeStyle)) { - using namespace winrt::Windows::UI::ViewManagement; - const auto settings = UISettings(); - - background = getSysColor(settings.GetColorValue(UIColorType::Background)); - textColor = getSysColor(settings.GetColorValue(UIColorType::Foreground)); - accent = getSysColor(settings.GetColorValue(UIColorType::Accent)); - } -#endif - - const QColor btnFace = background; - const QColor btnHighlight = getSysColor(COLOR_BTNHIGHLIGHT); - - result.setColor(QPalette::Highlight, accent); - result.setColor(QPalette::WindowText, getSysColor(COLOR_WINDOWTEXT)); - result.setColor(QPalette::Button, btnFace); - result.setColor(QPalette::Light, btnHighlight); - result.setColor(QPalette::Dark, getSysColor(COLOR_BTNSHADOW)); - result.setColor(QPalette::Mid, result.button().color().darker(150)); - result.setColor(QPalette::Text, textColor); - result.setColor(QPalette::PlaceholderText, placeHolderColor(textColor)); - result.setColor(QPalette::BrightText, btnHighlight); - result.setColor(QPalette::Base, getSysColor(COLOR_WINDOW)); - result.setColor(QPalette::Window, btnFace); - result.setColor(QPalette::ButtonText, getSysColor(COLOR_BTNTEXT)); - result.setColor(QPalette::Midlight, getSysColor(COLOR_3DLIGHT)); - result.setColor(QPalette::Shadow, getSysColor(COLOR_3DDKSHADOW)); - result.setColor(QPalette::HighlightedText, getSysColor(COLOR_HIGHLIGHTTEXT)); - - result.setColor(QPalette::Link, Qt::blue); - result.setColor(QPalette::LinkVisited, Qt::magenta); - result.setColor(QPalette::Inactive, QPalette::Button, result.button().color()); - result.setColor(QPalette::Inactive, QPalette::Window, result.window().color()); - result.setColor(QPalette::Inactive, QPalette::Light, result.light().color()); - result.setColor(QPalette::Inactive, QPalette::Dark, result.dark().color()); - - if (result.midlight() == result.button()) - result.setColor(QPalette::Midlight, result.button().color().lighter(110)); + using QWindowsApplication = QNativeInterface::Private::QWindowsApplication; + if (auto nativeWindowsApp = dynamic_cast<QWindowsApplication *>(QGuiApplicationPrivate::platformIntegration())) + nativeWindowsApp->lightSystemPalette(result); } static void populateDarkSystemBasePalette(QPalette &result) |