October 23, 2010

ShardCore ShardCore
Lab Rat
1 posts

[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?

5 replies

October 23, 2010

Denis Kormalev Denis Kormalev
Lab Rat
1607 posts

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.

October 23, 2010

Denis Kormalev Denis Kormalev
Lab Rat
1607 posts

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

2Moderators who have rights here: please move it.

October 23, 2010

ShardCore ShardCore
Lab Rat
1 posts

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.

October 23, 2010

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1274 posts

@Denis: Moved to desktop

October 24, 2010

Volker Volker
Ant Farmer
5331 posts

A simpler method might be to use QWidget::addAction [doc.trolltech.com] 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.

 
  ‹‹ QScriptable inheritance.      How to minimize memory usage in runtime ››

You must log in to post a reply. Not a member yet? Register here!