//main.qml
import QtQuick 2.3
Item {
id: item
width: 500
height: 500
function addItems() {
for (var i = 0; i < mainModel.count; i++) {
var component = Qt.createComponent("RectItem.qml");
if (component.status === Component.Ready) {
var childRec = component.createObject(item);
childRec.x = mainModel.get(i).x;
childRec.y = mainModel.get(i).y;
childRec.color = mainModel.get(i).color;
}
}
}
ListModel {
id: mainModel
ListElement {
x: 100
y: 110
color: "#123"
}
ListElement {
x: 450
y: 90
color: "#a63"
}
ListElement {
x: 90
y: 400
color: "#c13"
}
ListElement {
x: 120
y: 200
color: "#543"
}
ListElement {
x: 300
y: 177
color: "#fc3"
}
}
MouseArea {
id: mouse
anchors.fill: parent
onClicked: addItems()
}
}
// RectItem.qml
import QtQuick 2.0
Rectangle {
width: 50
height: 50
radius: 25
color: "#a33"
}
Repeater {
model: mainModel
anchors.fill: parent
Rectangle {
width: 100
height: 100
color: model.color
z: index
x: model.x
y: model.y
MouseArea {
anchors.fill: parent
onClicked: Qt.quit()
}
}
}
Repeater {
id: repeater
model: mainModel
anchors.fill: parent
property int counter: 0
Rectangle {
width: 100
height: 100
color: model.color
visible: index<=repeater.counter
z: index
x: model.x
y: model.y
MouseArea {
anchors.fill: parent
onClicked: {
repeater.counter++
}
}
}
}