I wonder why this doesn't work?
ListView {
id: root
property var selection: QtObject {}
...
delegate: MyView {
focused: ListView.isCurrentItem
selected: root.selection[index] === true
Rectangle {
id: selectionOverlay
anchors.fill: parent
color: "red"
opacity: 0.3
visible: selected
}
}
Keys.onPressed: if (event.key === Qt.Key_Space) {
if(!root.selection[root.currentIndex])
root.selection[root.currentIndex] = true;
else
root.selection[root.currentIndex] = false;
}
}
Namely, the delegate doesn't react on the changes in the selection object. Only when delegate for the index is recreated can the selection be seen (e.g. when scrolling far enough and back).
Changing root.selection[index] to ListView.view.selection[index] doesn't help either.
I need to have selection on the ListView level to manage multi-select stuff. Have been banging my head for some time.
Thanks!