How do I get the current editor from a QTableView?

qt

Solution

The delegate creates the editing widget, but does not store it and the view does not give access to it (presumably because it is not persistent).

So you will have to subclass `QStyledItemDelegate` and reimplement `createEditor(QWidget*, const QStyleOptionViewItem&, const QModelIndex&) const` to store a copy of the returned pointer. Then you can provide access to the editor through the delegate.

AFAIK you cannot create multiple editors at once in a single view, and delegate sharing across views is discouraged, so holding the last created editor should be sufficient. I would also create a private slot that nulls the pointer and connect it to the destroyed signal of the created editor - so you know it is always valid.

Problem

Is there a way of getting the editor (a QLineEdit instance) while the editing is in progress?

Original source