Does QML TreeView support signal layoutChanged emitted from model?

  • I have a model that works well with QTreeView. In the model I implemented a sort that looks like this:

    void SimpleTreeModel::sort(Node* sortedNode)
      emit layoutAboutToBeChanged(QList<QPersistentModelIndex>(), VerticalSortHint);
      QModelIndexList oldIndices = persistentIndexList();
      Node::SortType sortType = Node::Down;
      //sort starting node
      QModelIndexList newIndices;
      for(const auto &i : oldIndices)
          Node* node = const_cast<Node*>(nodeFromIndex(i));
          QModelIndex index = indexFromNode(node);
      changePersistentIndexList(oldIndices, newIndices);
      QModelIndex startingIndex = indexFromNode(sortedNode);
      emit layoutChanged({ QPersistentModelIndex(startingIndex) }, VerticalSortHint);

    when I call this function, QTreeView updates the view, but TreeView in QML don't do this. QML TreeView usage:

       model: treeModel
         title: "Title"
         role: "title"
         width: 700

    What am I doing wrong? Why the view does not update the layout of the elements after sorting?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.