现在有个布局,比如说是Column{},在里面添加createComponent()动态创建的组件,这时候布局失效了,每个新创建的组件都是在(0,0)位置处。代码简化可以大概是下面的样子,有没有大佬给看看是不是我什么地方错了?
比如说有一个qml文件 test.qml
Item {
id:root
RadioButton{
text:"测试一行"
}
}
// main.qml
ApplicationWindow{
id:root
height:640
width:480
visible:true
title:"测试"
function add(){
var component = Qt.createComponent("test.qml");
if (component.status == Component.Ready) {
var button = component.createObject(column);
}else{
console.log("Component.Error: ",component.errorString());
}
}
Column{
id:column
spacing:10
}
Button{
id:button
anchors{bottom:parent.bottom;bottomMargin:10;}
height:30;width:45;
onClicked:
add()
}
}