summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Skoland <davidskoland@gmail.com>2020-10-02 09:49:50 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-10-06 08:17:31 +0000
commit62fed23fefef0738ef55a17f96efd49e30313152 (patch)
treeaa76be9586fa05c92331ebdbcf81000114973cc8
parent48cc034c3fad709e7c145a3793d6521b944b36c2 (diff)
Improve QWizard visuals for macOS dark mode
This did not account for macOS dark mode, with hardcoded white, but now it correctly updates the colors from palette whenever the theme is changed. Additionally changed some bool checks to make sure the code runs on macOS theme updates. Do note that this change affects Qt Maintenance Tool (in a good way). Pick-to: 5.12 5.15 Change-Id: I6fb92d3f6c15a7ff83d0d8a30cf82477b6aba126 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Katja Marttila <katja.marttila@qt.io>
-rw-r--r--src/widgets/dialogs/qwizard.cpp40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp
index 2a8c87379a..f3dd4d5051 100644
--- a/src/widgets/dialogs/qwizard.cpp
+++ b/src/widgets/dialogs/qwizard.cpp
@@ -558,6 +558,7 @@ public:
QWizardLayoutInfo layoutInfoForCurrentPage();
void recreateLayout(const QWizardLayoutInfo &info);
void updateLayout();
+ void updatePalette();
void updateMinMaxSizes(const QWizardLayoutInfo &info);
void updateCurrentPage();
bool ensureButton(QWizard::WizardButton which) const;
@@ -860,6 +861,7 @@ void QWizardPrivate::switchToPage(int newId, Direction direction)
enableUpdates();
updateLayout();
+ updatePalette();
emit q->currentIdChanged(current);
}
@@ -1143,16 +1145,8 @@ void QWizardPrivate::recreateLayout(const QWizardLayoutInfo &info)
pageFrame->palette().brush(QPalette::Window).color().alpha() < 255
|| pageFrame->palette().brush(QPalette::Base).color().alpha() < 255;
if (mac) {
- if (!wasSemiTransparent) {
- QPalette pal = pageFrame->palette();
- pal.setBrush(QPalette::Window, QColor(255, 255, 255, 153));
- // ### The next line is required to ensure visual semitransparency when
- // ### switching from ModernStyle to MacStyle. See TAG1 below.
- pal.setBrush(QPalette::Base, QColor(255, 255, 255, 153));
- pageFrame->setPalette(pal);
- pageFrame->setAutoFillBackground(true);
- antiFlickerWidget->setAutoFillBackground(false);
- }
+ pageFrame->setAutoFillBackground(true);
+ antiFlickerWidget->setAutoFillBackground(false);
} else {
if (wasSemiTransparent)
pageFrame->setPalette(QPalette());
@@ -1293,6 +1287,30 @@ void QWizardPrivate::updateLayout()
updateMinMaxSizes(info);
}
+void QWizardPrivate::updatePalette() {
+ if (wizStyle == QWizard::MacStyle) {
+ // This is required to ensure visual semitransparency when
+ // switching from ModernStyle to MacStyle.
+ // See TAG1 in recreateLayout
+ // This additionally ensures that the colors are correct
+ // when the theme is changed.
+
+ // we should base the new palette on the default one
+ // so theme colors will be correct
+ QPalette newPalette = QApplication::palette(pageFrame);
+
+ QColor windowColor = newPalette.brush(QPalette::Window).color();
+ windowColor.setAlpha(153);
+ newPalette.setBrush(QPalette::Window, windowColor);
+
+ QColor baseColor = newPalette.brush(QPalette::Base).color();
+ baseColor.setAlpha(153);
+ newPalette.setBrush(QPalette::Base, baseColor);
+
+ pageFrame->setPalette(newPalette);
+ }
+}
+
void QWizardPrivate::updateMinMaxSizes(const QWizardLayoutInfo &info)
{
Q_Q(QWizard);
@@ -3147,6 +3165,8 @@ bool QWizard::event(QEvent *event)
if (event->type() == QEvent::StyleChange) { // Propagate style
d->setStyle(style());
d->updateLayout();
+ } else if (event->type() == QEvent::PaletteChange) { // Emitted on theme change
+ d->updatePalette();
}
#if QT_CONFIG(style_windowsvista)
else if (event->type() == QEvent::Show && d->vistaInitPending) {