diff options
author | Wladimir Leuschner <wladimir.leuschner@qt.io> | 2024-04-22 14:44:25 +0200 |
---|---|---|
committer | Wladimir Leuschner <wladimir.leuschner@qt.io> | 2024-04-26 02:24:54 +0200 |
commit | 7d7d843a3eacf11d2e9e5c2dd596f6daa3ab46f7 (patch) | |
tree | ace8bbcf2fcdccfde8a2d1ea298ca72b4464330b /src/plugins | |
parent | 98b034e53a7821018683c05d5dba776f0f2753f0 (diff) |
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
Pick-to: 6.7 6.7.1
Change-Id: Icb529124f63587e75bb56e40e8b1fcfe3c61c55d
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/styles/modernwindows/qwindows11style.cpp | 18 | ||||
-rw-r--r-- | src/plugins/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 a79aac76ef..daca801609 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<QAbstractScrollArea *>(widget); scrollarea && !qobject_cast<QMdiArea *>(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<QCommandLinkButton *>(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<QAbstractScrollArea *>(widget); + scrollarea && !qobject_cast<QMdiArea *>(widget)) { + const QPalette pal = scrollarea->viewport()->property("_q_original_background_palette").value<QPalette>(); + 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 90e368f1ea..9c54afd967 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: |