Shouldn't something like that work?
Column {
id: col
property int selectedIndex: -1
Repeater {
model: 5
Rectangle {
width: 200; height: 50
color: col.selectedIndex == index ? "red" : "white"
MouseArea {
anchors.fill: parent
onClicked: col.selectedIndex = index
}
}
}
}
Column {
id: col
property int selectedIndex: -1
Repeater {
model: 5
Rectangle {
width: 200; height: 50
color: col.selectedIndex == index ? "red" : "white"
MouseArea {
anchors.fill: parent
onClicked: col.selectedIndex = index
}
}
}
}
To copy to clipboard, switch view to plain text mode
You can easily create a component from it like so:
Column {
id: col
property alias delegate: rep.delegate
property alias model: rep.model
property int selectedIndex: -1
Repeater {
id: rep
}
}
Column {
id: col
property alias delegate: rep.delegate
property alias model: rep.model
property int selectedIndex: -1
Repeater {
id: rep
}
}
To copy to clipboard, switch view to plain text mode
If you really want to, you can adjust the delegate to add a MouseArea to the delegate to have everything contained in a single component, probably more or less like so:
Column {
id: col
property Component delegate
property alias model: rep.model
property int selectedIndex: -1
Repeater {
id: rep
}
Component {
id: macmp
MouseArea {
anchors.fill: parent
onClicked: col.selectedIndex = index
}
}
onDelegateChanged: {
var obj = delegate.createInstance(rep) // or create the item elsewhere and assign it to the rep.delegate
var ma = macmp.createInstance(obj)
}
}
Column {
id: col
property Component delegate
property alias model: rep.model
property int selectedIndex: -1
Repeater {
id: rep
}
Component {
id: macmp
MouseArea {
anchors.fill: parent
onClicked: col.selectedIndex = index
}
}
onDelegateChanged: {
var obj = delegate.createInstance(rep) // or create the item elsewhere and assign it to the rep.delegate
var ma = macmp.createInstance(obj)
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks