0

I want to change the children of a determined parent node in a QML treeview, I thought to iterate through every child and change the property that I want, but I don't know how to get the children list from a parent. I have the follow QML Menu:

TreeView { id: tree anchors.fill: parent model: model itemDelegate: CustomNode{ id: node Menu { id: menu MenuItem { text: "Show" onTriggered: { styleData.value.active = !!+state } } } MouseArea{ anchors.fill: parent acceptedButtons: Qt.LeftButton onClicked: { idNode = styleData.value.vredId menu.popup() } } } } 

When I click on the node it opens a menu that after clicked in the "Show" button change a property of the selected node, from this node I need to get its children and change the same property that was changed on the parent.

How can I do it?

1
  • It may be easier to implement this on the model side. Commented Apr 11, 2017 at 19:34

1 Answer 1

1

You can use a DelegateModel to obtain the QModelIndexes of the children.

DelegateModel { id:delegateModel rootIndex: styleData.index } delegateModel.count // returns the number of children delegateModel.modelIndex(i) // returns the model index of the ith element. 

Accessing the data for a given QModelIndex is still not that easy, but is already described in this post.

As suggested in my comment, it could be easier to implement this logic on the model side in C++.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.