From a59d60d4ff3d6ece48a61f664711c432179c8222 Mon Sep 17 00:00:00 2001 From: Wladimir Leuschner Date: Mon, 22 Apr 2024 14:44:25 +0200 Subject: [PATCH] Windows11Style:Save unpolished palette for QAbstractScrollArea::viewport When using QWindows11Style, the viewports background has to be set to Qt::transparent to have the effect of rounded corners in ItemViews and Combobox flyouts. Other Windows styles do not make use of transparent windows, so this polishment needs to be reverted in case the style changes. Other styles also do not manipulate the QAbstractScrollArea::viewport palette and thus changing color schemes results in not applying the new color scheme. Fixes: QTBUG-123928 Change-Id: Icb529124f63587e75bb56e40e8b1fcfe3c61c55d Reviewed-by: Oliver Wolff (cherry picked from commit 7d7d843a3eacf11d2e9e5c2dd596f6daa3ab46f7) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit 2141c7998ace98dbc4f2da283c6611055cdbc162) --- .../styles/modernwindows/qwindows11style.cpp | 18 ++++++++++++++---- .../styles/modernwindows/qwindows11style_p.h | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/plugins/styles/modernwindows/qwindows11style.cpp b/src/plugins/styles/modernwindows/qwindows11style.cpp index 45c53b714b3..a55193e5ab5 100644 --- a/src/plugins/styles/modernwindows/qwindows11style.cpp +++ b/src/plugins/styles/modernwindows/qwindows11style.cpp @@ -2020,11 +2020,11 @@ void QWindows11Style::polish(QWidget* widget) widget->setPalette(pal); } else if (const auto *scrollarea = qobject_cast(widget); scrollarea && !qobject_cast(widget)) { - QPalette pal = widget->palette(); - QColor backgroundColor = widget->palette().base().color(); - backgroundColor.setAlpha(255); - pal.setColor(scrollarea->viewport()->backgroundRole(), backgroundColor); + QPalette pal = scrollarea->viewport()->palette(); + const QPalette originalPalette = pal; + pal.setColor(scrollarea->viewport()->backgroundRole(), Qt::transparent); scrollarea->viewport()->setPalette(pal); + scrollarea->viewport()->setProperty("_q_original_background_palette", originalPalette); } else if (qobject_cast(widget)) { widget->setProperty("_qt_usingVistaStyle",false); QPalette pal = widget->palette(); @@ -2034,6 +2034,16 @@ void QWindows11Style::polish(QWidget* widget) } } +void QWindows11Style::unpolish(QWidget *widget) +{ + QWindowsVistaStyle::unpolish(widget); + if (const auto *scrollarea = qobject_cast(widget); + scrollarea && !qobject_cast(widget)) { + const QPalette pal = scrollarea->viewport()->property("_q_original_background_palette").value(); + scrollarea->viewport()->setPalette(pal); + scrollarea->viewport()->setProperty("_q_original_background_palette", QVariant()); + } +} /* The colors for Windows 11 are taken from the official WinUI3 Figma style at diff --git a/src/plugins/styles/modernwindows/qwindows11style_p.h b/src/plugins/styles/modernwindows/qwindows11style_p.h index 90e368f1ea4..9c54afd967a 100644 --- a/src/plugins/styles/modernwindows/qwindows11style_p.h +++ b/src/plugins/styles/modernwindows/qwindows11style_p.h @@ -48,6 +48,7 @@ public: int pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr, const QWidget *widget = nullptr) const override; void polish(QPalette &pal) override; + void unpolish(QWidget *widget) override; protected: QWindows11Style(QWindows11StylePrivate &dd); private: