Solved How to reset a full treeView ?
-
Hello everyone
First of all, I have to say I'm a total newby with QtQuick and prefer Widgets. However, I had to take a step in and to learn asap...and google can't answer all my issues, unfortunatly.I'm setting a copy option for some elements in my tree, edit those element on another page, then on complete resent the whole model and come back on the tree.
My issue is : the tree isn't updated between the two pages
I tried
emit dataChanged(QModelIndex(), QModelIndex());
but it doesn't seems to affect the tree.
moreover, the tree doesn't respond anymore to right click or expand, so I guess it has more or less been affected...but can't realy understand how.model function :
void TreeModel::rebuild() { cleanTree(rootItem); fillModelBuilding(m_buidlings.existingBuildingList()); emit dataChanged(QModelIndex(), QModelIndex()); }
view :
Item{ TreeView { width: parent.width height: parent.height id:buildingTreeId anchors.fill: parent model: siteTree MouseArea { anchors.fill: parent acceptedButtons: Qt.RightButton onReleased: { if (mouse.button === Qt.RightButton) { contextMenuArea.popup() } } } Menu { id: contextMenuArea MenuItem { text: qsTr('Copier l\'emplacement') onTriggered:{ stackView.pushItem({item: Qt.resolvedUrl("AreaCopyForm.qml")}) } } selection: ItemSelectionModel { id:sel model: siteTree } selectionMode: SelectionMode.SingleSelection TableViewColumn { role: "name_role" title: "Site" } }
I cleaned up the view to avoid too much "polution"...but I think all the important stuff is here
-
Hi and welcome to devnet,
The first strange thing is that you pass two invalid model indexes, so there's not reason for the views to update anything since both the top left and bottom right indexes points to nowhere in the model.
From the code of your function it rather looks like you are reseting your whole model. beginResetModel and endResetModel might be a better choice.
Hope it helps
-
@SGaist and it worked perfectly
Thank you a lot...I should bake you a cookie statue for this
I had found the two index idea here : [http://stackoverflow.com/questions/29141038/what-does-bottomright-mean-when-using-datachanged-with-a-qtreeview-in-qt]
but it clearly wasn't adapted for the situation. -
You're welcome !
A cookie statue ? Sounds delicious :)