[Moved] QTreeWidget ’Collapse/Expand all Same-Level’ Items
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?
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.
And this category is not appropriate for your thread. Desktop will fit better.
2Moderators who have rights here: please move it.
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.
@Denis: Moved to desktop
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.