Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Does QML TreeView support signal layoutChanged emitted from model?
Forum Updated to NodeBB v4.3 + New Features

Does QML TreeView support signal layoutChanged emitted from model?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 385 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Denis Demidovich
    wrote on last edited by
    #1

    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
      sortedNode->sortChildren(sortType);
    
      QModelIndexList newIndices;
      newIndices.reserve(oldIndices.size());
      for(const auto &i : oldIndices)
      {
          Node* node = const_cast<Node*>(nodeFromIndex(i));
          QModelIndex index = indexFromNode(node);
          newIndices.push_back(index);
      }
      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:

    TreeView
    {
       model: treeModel
       TableViewColumn 
       {
         title: "Title"
         role: "title"
         width: 700
       }
    }
    

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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved