PDA

View Full Version : Buttons to add new children/siblings on QTreeView entries



xadian
3rd September 2014, 13:47
Hi,

I want to build a QTreeView that displays a number of buttons on each row (such as "delete current row", "add sibling below this row", "add child below this row").
The three possibilities for this (that I see) are
- setIndexWiget() connected to a slot which uses the selection in the treeview to figure out where to insert/delete something
- a custom delegate - Is there a way for a delegate to figure out on which item it was activated (i.e. get the corresponding modelindex)?
- and of course to implement a custom view which seems like the most work.

My Questions are:
- Is there any important reason to pick one over the other (e.g. setIndexWiget() might not scale well for large numbers of tree items I assume. On the other hand delegates (as I currently understand them) may not actually be intended to be used to modify the model in such a way but rather only to modify data of model items)?
- Are there other options of doing this that may be better for some reason?
- And taking one step back: When implementing a list[-of-lists]* with such buttons on each list entry, is a QTreeView the right way to go in the first place?

Best,
xdn

anda_skoa
3rd September 2014, 14:23
A delegate knows which index it is currently displaying/editing.

If you data is, as you said, list of list, you could consier QColumnView, maybe with the buttons outside or on the preview widget.

Cheers,
_

xadian
3rd September 2014, 14:31
Good to know. In that case I would currently lean towards the custom delegate solution.
A QColumnView with a split view for hierarchies is not what I want. All lists should be displayed as in a single view with slight indentations. And buttons for these functions outside of the main widget is precisely what I want to avoid.

Note: I miswrote earlier, what I'm trying to visualize is actually a list[-of-lists]* .