i am using a QAbstractListModel subclass in a listview. And i want to be able to generate a new listmodel that is passed to QML through c++ based on which item was clicked.
what is the method to implement to able to tell which item was clicked in the list?
i have searched the web quite a bit but i cannot seem to find the best way to do it.
this code creates a grouplist that is shown as toplevel and it has a nested list that show beneath each item in the grouplist. The nested list obviously shows the children of the group.. so i need a way to get to the object that is being clicked so that i can use it in the back-end to generate new lists of its children.
the code is:
import QtQuick 2.4
import QtQuick.Window 2.2
//import ListMode 1.0
Rectangle {
height: 250
width: 140
color: "pink"
//property var aNum: 0
Component {
id: folderDelegate
Item {
width: 140
height: col2.childrenRect.height
Column {
id: col2
anchors.left: parent.left
anchors.right: parent.right
Rectangle {
height: 20
width: parent.width
border.color: "black"
MouseArea {
anchors.fill: parent
onClicked: console.log(folderlist.contentItem) <<== this is not enough
}
Text {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
id: name1
text: model.Name
}
}
}
}
}
ListView {
id: outer
model: myModel
delegate: groupsDelegate
anchors.fill: parent
}
Component {
id: groupsDelegate
Item {
width: 140
height: col.childrenRect.height
Column {
id: col
anchors.left: parent.left
anchors.right: parent.right
Text {
anchors.horizontalCenter: parent.horizontalCenter
id: t1
font.bold: true
font.underline: true
font.pointSize: 9
text: model.Name
}
ListView {
id: folderlist
model: treemodel.lists[treemodel.modIndex]
delegate: folderDelegate
contentHeight: contentItem.childrenRect.height
height: childrenRect.height
anchors.left: parent.left
anchors.right: parent.right
clip: true
}
}
}
}
}
instead of only getting the name of the item being clicked i would like to be able to get the actual object because i need to extract more data from the object to correctly identify the new children.
if you guys could help me out, i would appreciate it very much!
Thanks in advance!