diff options
author | Andy Shaw <andy.shaw@qt.io> | 2017-08-24 09:30:14 +0200 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2018-02-15 07:45:26 +0000 |
commit | d0dffdfc012574da4a75241097b667d09bb39ba2 (patch) | |
tree | 95a1ce711ff0f7792301aa912fbe09ab3214049c /src/widgets/itemviews/qabstractitemdelegate.cpp | |
parent | 8920bf32eebe03cfc8a1a5e97f5b34c09c79a11b (diff) |
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 <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets/itemviews/qabstractitemdelegate.cpp')
-rw-r--r-- | src/widgets/itemviews/qabstractitemdelegate.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
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<QFocusEvent *>(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) { |