ListView with ObjectModel and custom objects get index of selected object
-
Hello!
Is it possible to get the index of the selected item in an ObjectModel that is displayed with an ListView?
For example:
// A.qml Item { id: itemA property string name; Text { text: "A:" + name } } // B.qml Item { id: itemB property string name; Text { text: "B:" + name } } //List.qml ListView { property var objects; id: listViewExample model: objects } // main.qml List { objects: ObjectModel { A { name: "test"} B { name: "test"} } }
The reason is that i want to create multiple objects that can be displayed on one list, but each of them have a slightly different behaviour when clicked etc. This is a bit oversimplyfied here in this example.
However, the question remains. How can I get the index of the object in the components A and B in the custom implementation in files A.qml and B.qml. Note: the objects A and B should only be used in combo with the custom listview in List.qml (that is the goal at least)
Or from another perspective, how do I implement this cleanly to have a set of custom components in a list that notifies the above Listview when the custom component is clicked? The listview is displayed on a touchscreen that will scroll trough the list of items. And I want it to scroll to the selected item when selected.