forked from qt-creator/qt-creator
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:
@@ -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
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user