From 9a1b7c7fa59a5033344dd0b67b28de3531c92d69 Mon Sep 17 00:00:00 2001 From: Santhosh Kumar Date: Tue, 24 Jan 2023 10:49:53 +0100 Subject: [PATCH] Reset dark palettes for widgets to light in windows style Windows theme in dark mode set dark palettes for checkbox, radiobutton, menu, menubar explicitly. The fix added as part of a2518b4140ed88a674bf4a4fcf4576e35c698bb9 (to use light palette for windows style) overrides only system palette and widget specific palettes are still with dark palettes. In this patch, the windows style overwrite dark with light palette for widgets that are explicitly set with dark palette in windows theme. Fixes: QTBUG-110432 Pick-to: 6.5 Change-Id: I2af0e517d62981f062244eeab8f1b5e5442cc451 Reviewed-by: Volker Hilsheimer --- .../windowsvista/qwindowsvistastyle.cpp | 35 +++++++++++++++++++ .../windowsvista/qwindowsvistastyle_p.h | 1 + 2 files changed, 36 insertions(+) diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp index fc612c82e5..f884afc5b4 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp @@ -4811,6 +4811,41 @@ void QWindowsVistaStyle::polish(QPalette &pal) pal.setBrush(QPalette::AlternateBase, pal.base().color().darker(104)); } +/*! + \internal + */ +void QWindowsVistaStyle::polish(QApplication *app) +{ + // Override windows theme palettes to light + if (qApp->styleHints()->appearance() == Qt::Appearance::Dark) { + static const char* themedWidgets[] = { + "QToolButton", + "QAbstractButton", + "QCheckBox", + "QRadioButton", + "QHeaderView", + "QAbstractItemView", + "QMessageBoxLabel", + "QTabBar", + "QLabel", + "QGroupBox", + "QMenu", + "QMenuBar", + "QTextEdit", + "QTextControl", + "QLineEdit" + }; + for (const auto& themedWidget : std::as_const(themedWidgets)) { + auto defaultResolveMask = QApplication::palette().resolveMask(); + auto widgetResolveMask = QApplication::palette(themedWidget).resolveMask(); + if (widgetResolveMask != defaultResolveMask) + QApplication::setPalette(QApplication::palette(), themedWidget); + } + } + + QWindowsStyle::polish(app); +} + /*! \internal */ diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle_p.h b/src/plugins/styles/windowsvista/qwindowsvistastyle_p.h index b600491248..c437b3e434 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle_p.h +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle_p.h @@ -58,6 +58,7 @@ public: void polish(QWidget *widget) override; void unpolish(QWidget *widget) override; void polish(QPalette &pal) override; + void polish(QApplication *app) override; private: Q_DISABLE_COPY_MOVE(QWindowsVistaStyle)