Results 1 to 6 of 6

Thread: RemoveRows in QAbstractItemModel collapsing the entire QTreeView

  1. #1
    Join Date
    Jun 2018
    Location
    India
    Posts
    34
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Question RemoveRows in QAbstractItemModel collapsing the entire QTreeView

    Hi,

    I have a QTreeView with QAbstractItemModel (read- only). On click of a every node, I will be adding a dummy node called "Browsing" under the parent-node and delete it when the response comes to fill the QTreeview.

    Adding Dummy node and deleting it is working as expected as I am using beginInsertRows/endInsertRows/beginremoveRows/endRemoveRows. But the problem is, whenever the dummy node is getting deleted under any hierarchy, entire TreeView is getting collapsed to the topNode.

    Tried overriding the removeRows() function , but the behavior is still same. Please give some inputs on how do I delete a row without affecting the current tree expand/collapse view.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: RemoveRows in QAbstractItemModel collapsing the entire QTreeView

    Hi, please show us how you delete the "Browsing" entry.

    Ginsengelf

  3. #3
    Join Date
    Jun 2018
    Location
    India
    Posts
    34
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: RemoveRows in QAbstractItemModel collapsing the entire QTreeView

    Hi,

    Calling RemoveDummyBrowseNode() function whenever response comes back for a treenode.

    void TreeModel::RemoveDummyBrowseNode(TreeItem * parentNode)
    {
    TreeItem *child = parentNode->Child(0);

    if (nullptr != child)
    {
    QVariant data = child->Data();
    if (data == "Browsing...")
    {
    beginRemoveRows(parentNode->index, 0 , 0);
    parentNode->RemoveChild(0);
    endRemoveRows();
    }
    }
    }

    void TreeItem::RemoveChild(int position)
    {
    delete childNodeList.takeAt(position);
    }

  4. #4
    Join Date
    Jun 2018
    Location
    India
    Posts
    34
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: RemoveRows in QAbstractItemModel collapsing the entire QTreeView

    Hi, any help on this?

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: RemoveRows in QAbstractItemModel collapsing the entire QTreeView

    I know it is difficult (I have tried it), but have you watched what happens in the debugger when you execute this code? Somewhere in there, the tree view must be calling the code to collapse the tree. I can't see anything obvious in your code that should cause that, but maybe the tree view is thinking that all of the nodes have been modified, so nothing it is displaying can be trusted and it must be re-created. In that case, no expanded node can be trusted either, so all nodes must be collapsed.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  6. #6
    Join Date
    Jun 2018
    Location
    India
    Posts
    34
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: RemoveRows in QAbstractItemModel collapsing the entire QTreeView

    I checked the behavior of Editable TreeModel example where the view is getting updated without expanding/collapsing. Not sure about layoutChanged(), rowsAboutTobeRemoved() calls. Do I need to reimplement those too ?

Similar Threads

  1. Replies: 7
    Last Post: 11th September 2014, 15:02
  2. QTreeView with QAbstractItemModel
    By Fletcher in forum Qt Programming
    Replies: 4
    Last Post: 11th December 2009, 00:02
  3. removeRows in a QTreeView
    By mhoover in forum Qt Programming
    Replies: 2
    Last Post: 1st September 2009, 01:37
  4. Creating a QAbstractItemModel for QTreeView
    By hbill in forum Qt Programming
    Replies: 13
    Last Post: 14th August 2008, 17:01
  5. Need help with QTreeView/QAbstractItemModel
    By Valheru in forum Qt Programming
    Replies: 5
    Last Post: 28th August 2006, 16:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.