Расположение столбца не вступает в силу, когда последний созданный элемент добавляется в столбец
У меня есть макет столбца и элемент повторителя внутри столбца, теперь я хочу динамически добавить элемент (каждый элемент одинаков) в столбец, используя Qt.createComponent(). CreateObject(). Каждый элемент создается успешно, но макет столбца не не вступают в силу, и каждый элемент находится в (0,0)
ApplicationWindow {
id:root
visible: true
width: 640
height: 480
title: qsTr("Hello World")
property var component: null
property variant arr: [] // save latest creaed item
function add(){
if(component == null){
component = Qt.createComponent("Myself.qml"); // Myself.qml is a item designed by myslf and it's all right
}
if (component.status == Component.Ready) {
var button = component.createObject(column); // each item is created successfully
arr.push(button)
console.log("length=",arr.length)
}else{
console.log("Component.Error: ",component.errorString());
}
}
Button{
id:btn
anchors{bottom: parent.bottom;bottomMargin: 10;}
height: 30;
width:60;
text:qsTr("Click")
onClicked:
add(); // test function and every clicked an item will be created
}
ExclusiveGroup{
id:exclusiveGroup;
}
Rectangle{
id:rect
anchors{top:root.top;left:root.left;}
width: root.width/4
height: root.height/2
ScrollView{
id:scroll
anchors.fill:parent
Column{
id:column // here is column layout
spacing: 10
Repeater{
id:repeator
model:arr // model blined to arr
}
}
}
}
}