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. How to Temporarily Remove a QListWidget List Without Destroying the Custom Widgets Bound to QListWidgetItems
Forum Updated to NodeBB v4.3 + New Features

How to Temporarily Remove a QListWidget List Without Destroying the Custom Widgets Bound to QListWidgetItems

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 175 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.
  • K Offline
    K Offline
    kuqipair
    wrote on last edited by
    #1

    I want to temporarily clear a QListWidget. Since each QListWidgetItem in the list is bound to a custom widget, I need to ensure that when removing the list items, the custom widgets are preserved so I can quickly restore the QListWidget later.

    SGaistS 1 Reply Last reply
    0
    • S Offline
      S Offline
      SuhasKrishanamurthy
      wrote on last edited by
      #2

      To address this issue,

      1. Use takeItem() to remove QListWidgetItems one by one while saving pointers to the items and their associated widgets in a separate list.
      2. Reparent the widgets temporarily to avoid deletion.
      3. Instead of removing items, they can simply hide all items using QListWidgetItem::setHidden(true).
        This keeps the items in memory without actually removing them from the list.
      4. Use a Container to store removed items and their associated widgets.
        Later, reinsert them when restoring the list.
      1 Reply Last reply
      1
      • K kuqipair

        I want to temporarily clear a QListWidget. Since each QListWidgetItem in the list is bound to a custom widget, I need to ensure that when removing the list items, the custom widgets are preserved so I can quickly restore the QListWidget later.

        SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @kuqipair hi,

        Taking aside the fact that widget items should be used with caution or rather avoided (for performance reason, etc.), why not switch to a secondary empty QListWidget rather than doing all of that ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved