PDA

View Full Version : RemoveRows in QAbstractItemModel collapsing the entire QTreeView



chithara
27th May 2019, 10:56
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.

Ginsengelf
27th May 2019, 12:56
Hi, please show us how you delete the "Browsing" entry.

Ginsengelf

chithara
27th May 2019, 13:41
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);
}

chithara
28th May 2019, 04:44
Hi, any help on this?

d_stranz
28th May 2019, 06:13
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.

chithara
28th May 2019, 07:56
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 ?