[PyQt] how to close editor in QTreeView

Danny shevitz at lanl.gov
Fri Oct 8 17:55:11 BST 2010


Howdy,

In my application, I create a tree by drag and drop. When I drop an item, I
immediately open the item editor delegate so the user can type the item text.
I am implementing undo/redo, and both the item creation and text editing go
into a macro. All is good. 

The problem is that if I have the editor open and I begin another item
drop. The drop happens before the editor closes and my macro gets messed up.
This is all a long winded way of justifying that I need to programmatically close
an open item delegate if there is one at the beginning of the drop operation.

I can't get this to work. I have tried the following logic:

index = myTreeView.currentIndex()
delegate=myTreeView.itemDelegate(currentIndex)
myTreeView.closeEditor(delegate)

This fails with an error that closeEditor expects a QAbstractItemDelegate and a
QStyledItemDelegate.

So the question is, what is the easiest way to close the open QTreeView editor
(I'm in single selection mode, BTW)?

thanks,
Danny



More information about the PyQt mailing list