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 <burak.hancerli@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Thomas Hartmann
2023-01-04 10:40:26 +01:00
parent 56b9f99d76
commit c81f5ba7d1

View File

@@ -4,22 +4,46 @@ import QtQuick.Window 2.0
import QtQuick 2.0 import QtQuick 2.0
Window { Window {
id: window
property Item containedObject: null 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: { onContainedObjectChanged: {
if (window.writeGuard)
return
if (containedObject == undefined || containedObject == null) { if (containedObject == undefined || containedObject == null) {
visible = false visible = false
return return
} }
__resizeGuard = true
width = containedObject.width window.width = containedObject.width
height = containedObject.height window.height = containedObject.height
containedObject.parent = contentItem containedObject.parent = contentItem
visible = true window.visible = true
__resizeGuard = false }
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
} }