[PyQt] how to close editor in QTreeView

danny shevitz at lanl.gov
Wed Oct 13 15:59:30 BST 2010

> Either try using QAbstractItemView.closePersistentEditor() or, if you 
> need custom editors, create your own with a QStyledItemDelegate 
> subclass, where you have full control (including the widget, that 
> you're missing).
> Pete

Thanks for you response. What you suggested put me on the correct path to 
finally find what I was really looking for. It took me a few days to figure this
out, but it's really simple in the end.

(self is a QTreeView subclass):

index = self.currentIndex()
editor = self.indexWidget(index)
if editor:
    self.closeEditor(editor,  QAbstractItemDelegate.NoHint)

Worked like a charm! The hard part was figuring out that indexWidget, returned
to open editor if the item was being edited.

thanks again,

More information about the PyQt mailing list