Results 1 to 3 of 3

Thread: Delete a subtree in QTreeWidget

  1. #1

    Default Delete a subtree in QTreeWidget

    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

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: Delete a subtree in QTreeWidget

    If you are removing the item in top level then you can use
    Qt Code:
    1. QTreeWidgetItem * QTreeWidget::takeTopLevelItem ( int index )
    To copy to clipboard, switch view to plain text mode 
    this returns the item, then you have the ownership of it and have to delete it explicitly.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Delete a subtree in QTreeWidget

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to delete items in QTreeWidget...
    By Patrick Sorcery in forum Newbie
    Replies: 12
    Last Post: 10th September 2010, 10:41
  2. How to restrict directory viewing to a subtree?
    By xfurrier in forum Qt Programming
    Replies: 2
    Last Post: 10th April 2009, 17:29
  3. Replies: 4
    Last Post: 19th February 2009, 12:10
  4. Replies: 2
    Last Post: 17th March 2008, 13:53
  5. Delete items retrieved from QTreeWidget.takeItem
    By bruccutler in forum Qt Programming
    Replies: 3
    Last Post: 23rd March 2007, 00:24

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
  •  
Qt is a trademark of The Qt Company.