It might be easier to use a Repeater. Here is a working example that uses an array as a model (but you can replace it with a C++ model).
Item {
id: root
width: 1000; height: 600
property var model: [
{"x": 100, "y": 50, "color": "red"},
{"x": 60, "y": 320, "color": "blue"},
{"x": 360, "y": 210, "color": "green"}
]
Rectangle {
color: "gray"
width: 600
height: 400
anchors.centerIn: parent
border.color: Qt.darker(color)
border.width: 1
Repeater {
model: root.model
Item {
x: modelData.x
y: modelData.y
Rectangle {
width: 40; height: width; radius: width/2
color: modelData.color
anchors.centerIn: parent
border.color: Qt.darker(color)
border.width: 1
}
}
}
}
}
Item {
id: root
width: 1000; height: 600
property var model: [
{"x": 100, "y": 50, "color": "red"},
{"x": 60, "y": 320, "color": "blue"},
{"x": 360, "y": 210, "color": "green"}
]
Rectangle {
color: "gray"
width: 600
height: 400
anchors.centerIn: parent
border.color: Qt.darker(color)
border.width: 1
Repeater {
model: root.model
Item {
x: modelData.x
y: modelData.y
Rectangle {
width: 40; height: width; radius: width/2
color: modelData.color
anchors.centerIn: parent
border.color: Qt.darker(color)
border.width: 1
}
}
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks