I have implemented a custom QStyledItemDelegate for editing a cell in a QTableView. The delegate's editor is a QWidget with some radio buttons and two line edits. See the attached screenshots that show the editor widget as a delegate and parented with a QDialog.
The problem I am having is when the editor is used as a delegate. If I edit the text in either line edit and then press Tab, the editor is immediately closed. The new text is discarded and control goes back to the table view.
When used in a QDialog, the behavior is normal; Tab moves the focus to the next widget in the tab chain.
I have installed an event filter on both line edits and watch for FocusOut events. In delegate mode, editing one line edit and then -clicking- on the next generates a focus out event on the first line edit. Editing the first line edit and pressing Tab does not generate a focus out event.
I have tried setting window modality to Qt::ApplicationModal when using the editor as a delegate. This has no effect on behavior, even though the delegate reports that the editor "isModal" in all of the delegate methods (setEditorData(), setModelData(), updateEditorGeometry() etc.).
How do I make this editor behave like a modal dialog when used as a delegate? In other words, the user must be forced to click either Ok or Cancel to close the delegate? Do I need to install an event filter on the table view and intercept tabs when the delegate is active?
AsDelegate.jpg AsDialog.jpg
EDIT: Installing an event filter on the table view has no effect. After reading more of the QStyledItemDelegate docs, I see that it puts an event filter on the editor which intercepts the Tab key. Overriding this implementation in my derived delegate class has no effect, so it is likely the base class is getting the event first. If I explicitly install my own event filter on the editor class immediately after creating it, there is still no effect, so again, the base class must be getting it first.
Bookmarks