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. [Moved] QTreeWidget ’Collapse/Expand all Same-Level’ Items
QtWS25 Last Chance

[Moved] QTreeWidget ’Collapse/Expand all Same-Level’ Items

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 6.7k Views
  • 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.
  • S Offline
    S Offline
    ShardCore
    wrote on last edited by
    #1

    I have an existing app utilizing a QTreeWidget
    and i want to add a context menu to it containing things like
    'Collapse/Expand all Same-Level Entries' where it would collapse or expand all 'folder' entries at the same depth as the currently selected item, but only inside the same 'folder' as the currently selected item.

    Is there a way to do this without completely rewriting the code?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

      You can add event filter for your QTreeWidget which will listen for context menu events. After it you can get parent of current item and go through all its children to expand/collapse them.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DenisKormalev
        wrote on last edited by
        #3

        And this category is not appropriate for your thread. Desktop will fit better.

        2Moderators who have rights here: please move it.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          ShardCore
          wrote on last edited by
          #4

          thanks for the quick reply, and for the help.
          I just figured out, the guy who wrote the app I'm working on, actually created a custom widget class for the treeview i wanted to modify (then put a QTreeWidget on the next tab over), so any advice will probably be rendered useless. But thanks anyway.

          1 Reply Last reply
          0
          • ? This user is from outside of this forum
            ? This user is from outside of this forum
            Guest
            wrote on last edited by
            #5

            @Denis: Moved to desktop

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              A simpler method might be to use "QWidget::addAction ( QAction * action )":http://doc.trolltech.com/main-snapshot/qwidget.html#addAction to create a custom context menu. In the connected slot you can get the current or the selected item(s) and do the appropriate work.

              http://www.catb.org/~esr/faqs/smart-questions.html

              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