创建动态组件时候,如果在createObject函数里面没有设定组件的高宽度,则在组件的Component.onCompleted内部
获取的高度宽度是默认的,在组件的单击里面获取的高宽度才是后来设定的88。假如创建组件myW.qml
代码如下:
var componentFT = Qt.createComponent("myW.qml");
if (componentFT.status === Component.Ready)
{
var ftObj = componentFT.createObject(parent, {"folderName":"good name"/*, "width":88, "height":88*/});
ftObj.width = 88;
ftObj.height = 88;
}
如果在createObject函数里面设定组件的高宽度,则在组件的Component.onCompleted内部
获取的高度宽度是就是设定的,代码如下:
Component.onCompleted: {
var componentFT = Qt.createComponent("myW.qml");
if (componentFT.status === Component.Ready)
{
var ftObj = componentFT.createObject(parent, {"folderName":"good name", "width":88, "height":88});
}
}
-------------myW.qml如下----------------
import QtQuick 2.0
Rectangle {
width: 100 // 默认高度
height: 62
Component.onCompleted: console.log("compoent width=",width, "height=",height);
MouseArea{
id:idMa
anchors.fill: parent
onClicked: {
console.log("click, width=", width, "height=", height);
}
}
}