PDA

View Full Version : Delete a subtree in QTreeWidget



Suppaman
30th May 2011, 15:34
Hi all

I have a QtreeWidget control showing a tree of items. I need to remove an entire subtree of this main tree. My question is regarding the way to remove the subtree. I should navigate with a recursive alghoritm all the child items contained in the subtree and remove "manually" one by one or there is another way for delete an entire subtree in few lines of code?

Thank you for the help

Santosh Reddy
31st May 2011, 01:17
If you are removing the item in top level then you can use

QTreeWidgetItem * QTreeWidget::takeTopLevelItem ( int index )
this returns the item, then you have the ownership of it and have to delete it explicitly.

wysota
31st May 2011, 03:17
If you want to remove an item and all its children, you can just delete the item (call delete on it) and all children will get deleted as well.