Reputation: 4452
I have a dynamic set of QML components (these are based on/combine different controls like images, labels, ...) which are displayed on "arbitrary" positions within a parent control. The position of each component is defined by an underlying object (C++). At the moment I create and remove these components using dynamic object creation, everytime a new underlying object is created or removed.
Although this works it would be much cleaner to use a delegate/model scheme with an underlying QAbstractItemModel. Is there a built in component for this, e.g. a component which allows free positioning of the QAbstractItemModel's items?
[EDIT]: Here is a depiction of what I mean:
Regards,
Upvotes: 3
Views: 365
Reputation: 49329
You can use a Repeater
, which is typically used with a row or a column to lay things out, but it will also work for standalone items.
In addition to that you also have signals for added and removed items.
Repeater {
model: 20
delegate: Rectangle {
width: 50
height: 50
color: Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
MouseArea {
anchors.fill: parent
onPositionChanged: {
parent.x += mouseX
parent.y += mouseY
}
}
}
}
Upvotes: 3