From d0dffdfc012574da4a75241097b667d09bb39ba2 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 24 Aug 2017 09:30:14 +0200 Subject: Make sure the parent view will have focus when activation is given back When the focus is lost on an editor due to the application no longer being the active one then we have to ensure the parent view is going to get the focus when it is returned. Since the editor does not have focus when this check is done we need to manually account for this case by setting it on the parent view as if it would if the editor did have focus. Task-number: QTBUG-62253 Change-Id: I14ac347e9e3a2bfaa8715a45811b17c1c7cf15f8 Reviewed-by: Richard Moe Gustavsen --- src/widgets/itemviews/qabstractitemdelegate.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/widgets/itemviews') diff --git a/src/widgets/itemviews/qabstractitemdelegate.cpp b/src/widgets/itemviews/qabstractitemdelegate.cpp index 3268fda2fc..117de8edf9 100644 --- a/src/widgets/itemviews/qabstractitemdelegate.cpp +++ b/src/widgets/itemviews/qabstractitemdelegate.cpp @@ -526,7 +526,15 @@ bool QAbstractItemDelegatePrivate::editorEventFilter(QObject *object, QEvent *ev if (tryFixup(editor)) emit q->commitData(editor); + // If the application loses focus while editing, then the focus needs to go back + // to the itemview when the editor closes. This ensures that when the application + // is active again it will have the focus on the itemview as expected. + const bool manuallyFixFocus = (event->type() == QEvent::FocusOut) && !editor->hasFocus() && + editor->parentWidget() && + (static_cast(event)->reason() == Qt::ActiveWindowFocusReason); emit q->closeEditor(editor, QAbstractItemDelegate::NoHint); + if (manuallyFixFocus) + editor->parentWidget()->setFocus(); } #ifndef QT_NO_SHORTCUT } else if (event->type() == QEvent::ShortcutOverride) { -- cgit v1.2.3