【发布时间】:2016-03-27 01:48:17
【问题描述】:
我在 QML 中创建动态组件如下:
var component = Qt.createComponent("PlayerWindow.qml")
if (component.status != component.errorString())
console.log(component.errorString())
var playerWin = component.createObject(rootWindow);
rootWindow 是我的主应用程序窗口。现在,PlayerWindow 非常简单:
Window {
id: playerWindow
width: parent.width
height: parent.height
Component.onCompleted: {
console.log(parent.width)
console.log(rootWindow.height)
}
}
问题是parent.width 和rootWindow.width 的值确实不同,这在显示窗口时也很明显。但是,rootWindow 在createObject 调用中被设置为父级。所以,我不确定那里发生了什么,但我想知道这是否是在动态创建组件父组件时设置它们的正确方法。
【问题讨论】: