aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSanthosh Kumar <santhosh.kumar.selvaraj@qt.io>2025-09-02 21:41:48 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2025-10-28 12:34:45 +0000
commitc2e2bbc01cfaeb39be1b7815848b0147496f2c4e (patch)
tree59475d32ea155fbb0f083c13f8a5fa4887c4c55a
parenta2e6c6cdec6ad9fbc757be198ec69921c6ce7652 (diff)
Propagate attached properties for items within the popup window
The attached property doesn't propagate to the sub-menu items within the pop when the pop-up type is configured as Popup.Window, as the attached property, is provided only for the immediate window (made as part of patch d824585075b0abaec12c0cbb6445aa4eb84b2cea) and not further up. This patch ensures that the attached property is provided for the window if configured for anything further up in the hierarchy. Fixes: QTBUG-139603 Pick-to: 6.9 6.8 Change-Id: I95b9f735b7e19ad9916562bf09445fd20f2ba1f4 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> (cherry picked from commit e51223c77ca9ff05e7a2db8e7598c762a9918b9b) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quickcontrols/qquickattachedpropertypropagator.cpp16
-rw-r--r--tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml19
2 files changed, 31 insertions, 4 deletions
diff --git a/src/quickcontrols/qquickattachedpropertypropagator.cpp b/src/quickcontrols/qquickattachedpropertypropagator.cpp
index 962f25b908..166e87f7fc 100644
--- a/src/quickcontrols/qquickattachedpropertypropagator.cpp
+++ b/src/quickcontrols/qquickattachedpropertypropagator.cpp
@@ -178,12 +178,20 @@ static QQuickAttachedPropertyPropagator *findAttachedParent(const QMetaObject *o
QQuickPopup *popup = qobject_cast<QQuickPopup *>(objectWeAreAttachedTo);
if (popup) {
qCDebug(lcAttached).noquote() << "- attachee is a popup; checking its window";
- auto* popupWindow = popup->popupItem()->window();
- auto *object = attachedObject(ourAttachedType, popupWindow);
+ auto *window = popup->popupItem()->window();
+ auto *object = attachedObject(ourAttachedType, window);
// Check if the attached object exists for the popup window. If it
// doesn't, use transient parent attached object
- if (!object && qobject_cast<QQuickPopupWindow *>(popupWindow))
- return attachedObject(ourAttachedType, popupWindow->transientParent());
+ if (!object && qobject_cast<QQuickPopupWindow *>(window)) {
+ auto *transientParentWnd = window->transientParent();
+ do {
+ object = attachedObject(ourAttachedType, transientParentWnd);
+ if (object)
+ break;
+ transientParentWnd = transientParentWnd->transientParent();
+ } while (transientParentWnd);
+ qCDebug(lcAttached).noquote() << "- attached object of the transient parent window: " << object;
+ }
return object;
}
}
diff --git a/tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml b/tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml
index 9567509abb..47ed0b95a0 100644
--- a/tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml
+++ b/tests/auto/quickcontrols/qquickmaterialstyle/data/tst_material.qml
@@ -837,6 +837,17 @@ TestCase {
property GroupBox groupbox: GroupBox { Material.elevation: 10 }
property Frame frame: Frame { Material.elevation: 10 }
property Menu menu: Menu { }
+ property Menu menu_window_propagate: Menu {
+ readonly property var childItem: _subSubMenuItem
+ popupType: Popup.Window
+ onOpened: _subMenuItem.open()
+ Menu {
+ id: _subMenuItem
+ onOpened: _subSubMenuItem.open()
+ Menu { id: _subSubMenuItem }
+ }
+ Component.onCompleted: this.open()
+ }
property Page page: Page { }
property Pane pane: Pane { }
property Popup popup: Popup { }
@@ -854,6 +865,7 @@ TestCase {
{ tag: "groupbox", inherit: true },
{ tag: "frame", inherit: true },
{ tag: "menu", inherit: true },
+ { tag: "menu_window_propagate", inherit: true, propagate: true },
{ tag: "page", inherit: true },
{ tag: "pane", inherit: true },
{ tag: "popup", inherit: true },
@@ -874,6 +886,13 @@ TestCase {
control.parent = window.contentItem
control.visible = true
+ if (data.propagate) {
+ control = control.childItem
+ if (control instanceof T.Menu) {
+ tryCompare(control, "opened", true)
+ }
+ }
+
let defaultBackground = control.background.color
window.Material.background = "#ff0000"