From c81f5ba7d144d18d042963c11da4ff2cb160a8fb Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Wed, 4 Jan 2023 10:40:26 +0100 Subject: [PATCH] QmlDesigner: Fix resizeToItem with live preview The live preview recreates the "containedObject" and reparents it to the window. But the containedObject was not tracking this. Now we track the children accordingly. Using bindings to keep the size in sync. Change-Id: I051e9621f150befffec548ae0bbd431bd18480ce Reviewed-by: Burak Hancerli Reviewed-by: Reviewed-by: Thomas Hartmann --- .../qmlruntime/content/resizeItemToWindow.qml | 44 ++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/src/tools/qml2puppet/runnerconf/qmlruntime/content/resizeItemToWindow.qml b/src/tools/qml2puppet/runnerconf/qmlruntime/content/resizeItemToWindow.qml index ca4618ba734..7b99d4530a9 100644 --- a/src/tools/qml2puppet/runnerconf/qmlruntime/content/resizeItemToWindow.qml +++ b/src/tools/qml2puppet/runnerconf/qmlruntime/content/resizeItemToWindow.qml @@ -4,22 +4,46 @@ import QtQuick.Window 2.0 import QtQuick 2.0 Window { + id: window property Item containedObject: null - property bool __resizeGuard: false + + readonly property Item firstChild: window.contentItem.children.length > 0 ? window.contentItem.children[0] : null + + property bool writeGuard: false + + onFirstChildChanged: { + window.writeGuard = true + window.containedObject = window.firstChild + window.writeGuard = false + } + onContainedObjectChanged: { + if (window.writeGuard) + return + if (containedObject == undefined || containedObject == null) { visible = false return } - __resizeGuard = true - width = containedObject.width - height = containedObject.height + + window.width = containedObject.width + window.height = containedObject.height + containedObject.parent = contentItem - visible = true - __resizeGuard = false + window.visible = true + } + + Binding { + target: window.firstChild + when: window.firstChild + property: "height" + value: window.height + } + + Binding { + target: window.firstChild + when: window.firstChild + property: "width" + value: window.width } - onWidthChanged: if (!__resizeGuard && containedObject) - containedObject.width = width - onHeightChanged: if (!__resizeGuard && containedObject) - containedObject.height = height }