Search code examples
qtqtreeview

QTreeView item editor: how to make it only commit the edit on Enter press?


By default, the editor commits the data on Enter press, Tab press or focus change. I need to discard edits on focus change or Tab press instead of committing them to the model. How do I do that? I already have my own delegate class, can I do it with its help?


Solution

  • You should take a look at what is going on for base class :

    $QT482DIR/src/gui/itemviews/qitemdelegate.cpp

    bool QItemDelegate::eventFilter(QObject *object, QEvent *event)
    

    And overload this method to change the default behaviour. Just taking a look at it, I would follow commitData() and closeEditor() calls. As well as _q_commitDataAndCloseEditor to see what's going on