While skimming the QML Documentation, I found this commendable documented class: ItemSelectionModel
There is the C++-Class QItemSelectionModel
which provides some more detail on it's purpose to keep track on the selection of Items within a model.
However on the QML-Side I have not the slightes clue, on how to use it.
Lets say, I have this ListModel
ListModel {
id: lm
ListElement { value: 0 }
ListElement { value: 0 }
ListElement { value: 0 }
ListElement { value: 0 }
ListElement { value: 1 }
ListElement { value: 1 }
ListElement { value: 2 }
ListElement { value: 2 }
ListElement { value: 0 }
ListElement { value: 0 }
ListElement { value: 2 }
ListElement { value: 2 }
}
Now I have a View
in which I display all of this model, and a second view in which I only want to display a selection of it. So I created a ItemSelectionModel
and called the select
-method of it from the delegates of the first view which seemed to have no effect at all. Not even the hasSelection
-property bothered to change.
Repeater {
model: lm
delegate: Rectangle {
property int row: Math.floor(index / 4)
property int column: index % 4
width: 100
height: 100
x: 100 * column
y: 100 * row
border.color: 'black'
MouseArea {
anchors.fill: parent
onClicked: {
ism.select(index, ItemSelectionModel.Select | ItemSelectionModel.Current)
console.log(ism.hasSelection)
}
}
}
}
ItemSelectionModel {
id: ism
model: lm
}
So I wonder what is the purpose of this Component, that seems to do nothing at all. Or, how can I get it to do something purposeful?