From 44e5f7f29c29811534ca02359fe5b4fbe1f54990 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Fri, 11 Jun 2021 14:19:17 +0200 Subject: Use Inactive color group in inactive windows A palette has three color groups (Active, Inactive, Disabled), but we only listened to changes of the enabled state, and always used the Active color group for an enabled item. In order for the Inactive color group to take effect, we need to also trigger the update when the "active" property changes. Instead of connecting yet another signal, deliver WindowActivate/Deactivate to as well, and forward from contentItem to all children which can then update the current color group. Add a test case. Fixes: QTBUG-93752 Change-Id: I4f2b6121e822115aaa5c4faaa5d402932dacc67b Reviewed-by: Mitch Curtis (cherry picked from commit 3675f2b235f32e05cf6d754e81e0e8f8ddd59752) Reviewed-by: Qt Cherry-pick Bot --- src/quick/items/qquickitem.cpp | 7 +++++++ src/quick/items/qquickpaletteproviderprivatebase_p.h | 11 ++++++++--- src/quick/items/qquickwindow.cpp | 4 ++++ 3 files changed, 19 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index 7fe057ad70..5b8048c303 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -8505,6 +8505,13 @@ bool QQuickItem::event(QEvent *ev) for (QQuickItem *item : d->childItems) QCoreApplication::sendEvent(item, ev); break; + case QEvent::WindowActivate: + case QEvent::WindowDeactivate: + if (d->palette()) + d->setCurrentColorGroup(); + for (QQuickItem *item : d->childItems) + QCoreApplication::sendEvent(item, ev); + break; default: return QObject::event(ev); } diff --git a/src/quick/items/qquickpaletteproviderprivatebase_p.h b/src/quick/items/qquickpaletteproviderprivatebase_p.h index b1b5958329..9399462130 100644 --- a/src/quick/items/qquickpaletteproviderprivatebase_p.h +++ b/src/quick/items/qquickpaletteproviderprivatebase_p.h @@ -49,7 +49,7 @@ #include #include - +#include #include QT_BEGIN_NAMESPACE @@ -150,6 +150,9 @@ public: */ virtual void updateChildrenPalettes(const QPalette &parentPalette); +protected: + void setCurrentColorGroup(); + private: using PalettePtr = std::unique_ptr; using Self = QQuickPaletteProviderPrivateBase; @@ -160,7 +163,6 @@ private: QQuickPalette *windowPalette() const; - void setCurrentColorGroup(); void connectItem(); @@ -336,7 +338,10 @@ void QQuickPaletteProviderPrivateBase::setCurrentColorGroup() if constexpr (!isRootWindow()) { if (paletteData()) { const bool enabled = itemWithPalette()->isEnabled(); - paletteData()->setCurrentGroup(enabled ? QPalette::Active : QPalette::Disabled); + const auto window = itemWithPalette()->window(); + const bool active = window ? window->isActive() : true; + paletteData()->setCurrentGroup(enabled ? (active ? QPalette::Active : QPalette::Inactive) + : QPalette::Disabled); } } } diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index e6bfde66ae..85df4a66b3 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -1512,6 +1512,10 @@ bool QQuickWindow::event(QEvent *e) case QEvent::WindowDeactivate: if (auto da = d->deliveryAgentPrivate()) da->handleWindowDeactivate(this); + Q_FALLTHROUGH(); + case QEvent::WindowActivate: + if (d->contentItem) + QCoreApplication::sendEvent(d->contentItem, e); break; default: break; -- cgit v1.2.3