summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Skoland <davidskoland@gmail.com>2020-10-02 09:49:50 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-10-12 13:48:09 +0000
commit489c983864f1d778b5dd3a34b53f37a1e3adc4aa (patch)
tree91a922a1f7803c9913069c14b3e5f1b3a4137c66
parent259b7638fcd82bff05903fbb38d1d053855c1dc5 (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). Change-Id: I6fb92d3f6c15a7ff83d0d8a30cf82477b6aba126 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Katja Marttila <katja.marttila@qt.io> (cherry picked from commit 62fed23fefef0738ef55a17f96efd49e30313152) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-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 f19a4e99af..29f9efb68a 100644
--- a/src/widgets/dialogs/qwizard.cpp
+++ b/src/widgets/dialogs/qwizard.cpp
@@ -601,6 +601,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;
@@ -898,6 +899,7 @@ void QWizardPrivate::switchToPage(int newId, Direction direction)
enableUpdates();
updateLayout();
+ updatePalette();
emit q->currentIdChanged(current);
}
@@ -1179,16 +1181,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());
@@ -1329,6 +1323,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);
@@ -3174,6 +3192,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) {