aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2024-02-15 15:26:59 +0800
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-03-08 07:15:47 +0000
commitd396eeffda2244d22c3fc40814064fb184427c56 (patch)
treeb42c1d3b126280cac1c5ba6817ef0ac77345e83d
parentb008bf934a7af6a7b37f5995ef15644dc8be294f (diff)
QQuickAttachedPropertyPropagator: fix child window propagation
After the recent changes to window code, a child window's transient parent is not available as early as it used to be. Account for this by listening to changes in the window's parent as we do for items. Fixes: QTBUG-122008 Change-Id: I2cd93e3c487e7ce4567e740886ef65a756c1350f Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit 5f7b25a694eb46cc520b6dd2651f1e3f99e310f0) Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 9ca9468ffd464c9b131dfe2f7170c34a2d1413c7) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quickcontrols/qquickattachedpropertypropagator.cpp48
-rw-r--r--tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml39
2 files changed, 66 insertions, 21 deletions
diff --git a/src/quickcontrols/qquickattachedpropertypropagator.cpp b/src/quickcontrols/qquickattachedpropertypropagator.cpp
index 855f48ad0a..251e81b164 100644
--- a/src/quickcontrols/qquickattachedpropertypropagator.cpp
+++ b/src/quickcontrols/qquickattachedpropertypropagator.cpp
@@ -227,6 +227,7 @@ public:
void setAttachedParent(QQuickAttachedPropertyPropagator *parent);
void itemWindowChanged(QQuickWindow *window);
+ void transientParentWindowChanged(QWindow *newTransientParent);
void itemParentChanged(QQuickItem *item, QQuickItem *parent) override;
QList<QQuickAttachedPropertyPropagator *> attachedChildren;
@@ -235,22 +236,37 @@ public:
void QQuickAttachedPropertyPropagatorPrivate::attachTo(QObject *object)
{
- QQuickItem *item = findAttachedItem(object);
- if (item) {
+ if (QQuickItem *item = findAttachedItem(object)) {
connect(item, &QQuickItem::windowChanged, this, &QQuickAttachedPropertyPropagatorPrivate::itemWindowChanged);
QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Parent);
+ } else if (auto *window = qobject_cast<QQuickWindow *>(object)) {
+ QObjectPrivate::connect(window, &QWindow::transientParentChanged, this,
+ &QQuickAttachedPropertyPropagatorPrivate::transientParentWindowChanged);
}
}
void QQuickAttachedPropertyPropagatorPrivate::detachFrom(QObject *object)
{
- QQuickItem *item = findAttachedItem(object);
- if (item) {
+ if (QQuickItem *item = findAttachedItem(object)) {
disconnect(item, &QQuickItem::windowChanged, this, &QQuickAttachedPropertyPropagatorPrivate::itemWindowChanged);
QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Parent);
+ } else if (auto *window = qobject_cast<QQuickWindow *>(object)) {
+ QObjectPrivate::disconnect(window, &QWindow::transientParentChanged,
+ this, &QQuickAttachedPropertyPropagatorPrivate::transientParentWindowChanged);
}
}
+static QString debugName(QQuickAttachedPropertyPropagator *attached)
+{
+ QString string;
+ QDebug stream(&string);
+ if (!attached)
+ stream << "(null)";
+ else
+ stream.nospace().noquote() << attached << " (which is attached to " << attached->parent() << ')';
+ return string;
+}
+
/*!
\internal
@@ -276,14 +292,14 @@ void QQuickAttachedPropertyPropagatorPrivate::setAttachedParent(QQuickAttachedPr
return;
QQuickAttachedPropertyPropagator *oldParent = attachedParent;
- qCDebug(lcAttached) << "setAttachedParent called on" << q->parent();
+ qCDebug(lcAttached).noquote() << "setAttachedParent called on" << debugName(q) << "with parent" << debugName(parent);
if (attachedParent) {
- qCDebug(lcAttached) << "- removing ourselves as an attached child of" << attachedParent->parent() << attachedParent;
+ qCDebug(lcAttached).noquote() << "- removing ourselves as an attached child of" << debugName(attachedParent);
QQuickAttachedPropertyPropagatorPrivate::get(attachedParent)->attachedChildren.removeOne(q);
}
attachedParent = parent;
if (parent) {
- qCDebug(lcAttached) << "- adding ourselves as an attached child of" << parent->parent() << parent;
+ qCDebug(lcAttached).noquote() << "- adding ourselves as an attached child of" << debugName(parent);
QQuickAttachedPropertyPropagatorPrivate::get(parent)->attachedChildren.append(q);
}
q->attachedParentChange(parent, oldParent);
@@ -293,13 +309,24 @@ void QQuickAttachedPropertyPropagatorPrivate::itemWindowChanged(QQuickWindow *wi
{
Q_Q(QQuickAttachedPropertyPropagator);
QQuickAttachedPropertyPropagator *attachedParent = nullptr;
- qCDebug(lcAttached) << "window of" << q->parent() << "changed to" << window;
+ qCDebug(lcAttached).noquote() << "window of" << debugName(q) << "changed to" << window;
attachedParent = findAttachedParent(q->metaObject(), q->parent());
if (!attachedParent)
attachedParent = attachedObject(q->metaObject(), window);
setAttachedParent(attachedParent);
}
+void QQuickAttachedPropertyPropagatorPrivate::transientParentWindowChanged(QWindow *newTransientParent)
+{
+ Q_Q(QQuickAttachedPropertyPropagator);
+ QQuickAttachedPropertyPropagator *attachedParent = nullptr;
+ qCDebug(lcAttached).noquote() << "transient parent window of" << q << "changed to" << newTransientParent;
+ attachedParent = findAttachedParent(q->metaObject(), q->parent());
+ if (!attachedParent)
+ attachedParent = attachedObject(q->metaObject(), newTransientParent);
+ setAttachedParent(attachedParent);
+}
+
void QQuickAttachedPropertyPropagatorPrivate::itemParentChanged(QQuickItem *item, QQuickItem *parent)
{
Q_Q(QQuickAttachedPropertyPropagator);
@@ -383,14 +410,15 @@ QQuickAttachedPropertyPropagator *QQuickAttachedPropertyPropagator::attachedPare
void QQuickAttachedPropertyPropagator::initialize()
{
Q_D(QQuickAttachedPropertyPropagator);
+ qCDebug(lcAttached) << "initialize called for" << parent() << "- looking for attached parent...";
QQuickAttachedPropertyPropagator *attachedParent = findAttachedParent(metaObject(), parent());
if (attachedParent)
d->setAttachedParent(attachedParent);
const QList<QQuickAttachedPropertyPropagator *> attachedChildren = findAttachedChildren(metaObject(), parent());
- qCDebug(lcAttached) << "initialize called for" << parent() << "- found" << attachedChildren.size() << "attached children";
+ qCDebug(lcAttached) << "- found" << attachedChildren.size() << "attached children:";
for (QQuickAttachedPropertyPropagator *child : attachedChildren) {
- qCDebug(lcAttached) << "-" << child->parent();
+ qCDebug(lcAttached) << " -" << child->parent();
QQuickAttachedPropertyPropagatorPrivate::get(child)->setAttachedParent(this);
}
}
diff --git a/tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml b/tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml
index 4fb19c7c0f..6d7fbffa64 100644
--- a/tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml
+++ b/tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml
@@ -51,17 +51,6 @@ TestCase {
}
Component {
- id: styledWindowComponent
- Window {
- Material.theme: Material.Dark
- Material.primary: Material.Brown
- Material.accent: Material.Green
- Material.background: Material.Yellow
- Material.foreground: Material.Grey
- }
- }
-
- Component {
id: buttonLoaderComponent
Loader {
active: false
@@ -1277,4 +1266,32 @@ TestCase {
// false => true => false.
compare(buttonActiveFocusSpy.count, 2)
}
+
+ Component {
+ id: childWindowComponent
+
+ ApplicationWindow {
+ objectName: "parentWindow"
+ property alias childWindow: childWindow
+
+ Material.theme: Material.Dark
+ Material.primary: Material.Brown
+ Material.accent: Material.Green
+ Material.background: Material.Yellow
+ Material.foreground: Material.Grey
+
+ ApplicationWindow {
+ id: childWindow
+ objectName: "childWindow"
+ }
+ }
+ }
+
+ function test_windowBackgroundColorPropagation() {
+ let parentWindow = createTemporaryObject(childWindowComponent, testCase)
+ verify(parentWindow)
+
+ let childWindow = parentWindow.childWindow
+ compare(childWindow.Material.theme, Material.Dark)
+ }
}