PDA

View Full Version : how to manually call an instance of QStyledItemDelegate



iwatsu
1st February 2012, 21:21
I'm using a QStyledItemDelegate to edit the text of a QTreeWidgetItem when I double click on it.
Now I want the same functionality (renaming the item) when the user selects it through the context menu of the treewidget item.

Is it possible to call the createEditor() function of the delegate when the user selects the option through the context menu?

Thanks!

wysota
1st February 2012, 23:05
Isn't it easier to just call QAbstractItemView::edit()?

iwatsu
2nd February 2012, 00:32
Isn't it easier to just call QAbstractItemView::edit()?

Do you mean instead of using the delegate? I need the delegate since I either create a custom button for children items or a line edit for all top-level items. Is there no way to manually use the delegate and call the create function when using the context menu and not a trigger option like double click?
Thanks

wysota
2nd February 2012, 09:31
The delegate is associated with a (subset of) view. If you call edit() on the view, the view will call createEditor() of the delegate associated with the index you want to edit.


Is there no way to manually use the delegate and call the create function when using the context menu and not a trigger option like double click?

Sure you can call it but then you'll just get a widget floating around somewhere and unrelated in any way to the item you want to edit. If you want to edit an item then call edit().