Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What is the proper way to rebuild QTreeWidget hierachy
Qt 6.11 is out! See what's new in the release blog

What is the proper way to rebuild QTreeWidget hierachy

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 492 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    In my application I need to be able to rebuild QTreeWidget hierarchy. Conceptually, I need to remove all tree nodes following some number of top level nodes and then add their replacements. I am confused how I need to use existing APIs to do the removal in order to achieve what I need.

    I started by coding something like
    @for( QTreeWidgetItem * item = tree.topLevelItem(3); item != nullptr; item = tree.topLevelItem(3) )
    tree.removeItemWidget(item);
    @
    but quickly discovered that this loop never terminates. Subsequently I replaced the code with
    @for( QTreeWidgetItem * item = tree.takeTopLevelItem(3); item != nullptr; item = tree.takeTopLevelItem(3) )
    delete item;
    @
    This seems to produce desired effects on the screen. Can someone confirm that (a) this is a way I am expected to do it and (b) I am expected to delete no longer needed QTreeWidgetItems myself.

    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