From cfa85c76c7c7e1622cb02edcbbc3d948edca1e7f Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 29 Oct 2013 23:10:15 +0100 Subject: QWindowPrivate: add virtual function 'clearFocusObject' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On mobile platforms, a line edit should only have keyboard focus when the virtual keyboard is open. As it stands, the only way to clear focus when the user hides the keyboard, is to deactivate the whole window. This is a bit too much, since Qt still expects the window in front to be active/focused. What we need is a way to remove focus from the current focus object without disturbing the state of the window. QWindow has a virtual function 'focusObject' from before. We now add a virtual function 'clearFocusObject' to QWindowPrivate that can be overridden by QWidgetWindowPrivate and QQuickWindowPrivate. That way we can remove focus from current focus object when the virtual keyboard is closed from the platform plugins. Change-Id: Ica4ec76f8a69cd6107236a8000ff8bd742e988b5 Reviewed-by: Tor Arne Vestbø Reviewed-by: Friedemann Kleint Reviewed-by: Eskil Abrahamsen Blomfeldt Reviewed-by: Gunnar Sletta --- src/gui/kernel/qwindow.cpp | 4 ++++ src/gui/kernel/qwindow_p.h | 2 ++ src/widgets/kernel/qwidgetwindow.cpp | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 13218fa178..a3841d3cfb 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -367,6 +367,10 @@ void QWindowPrivate::setScreen(QScreen *newScreen, bool recreate) } } +void QWindowPrivate::clearFocusObject() +{ +} + /*! Sets the \a surfaceType of the window. diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h index f43c1ea8ec..8d8fca3ce6 100644 --- a/src/gui/kernel/qwindow_p.h +++ b/src/gui/kernel/qwindow_p.h @@ -129,6 +129,8 @@ public: void setScreen(QScreen *newScreen, bool recreate); + virtual void clearFocusObject(); + QWindow::SurfaceType surfaceType; Qt::WindowFlags windowFlags; QWindow *parentWindow; diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index 51a0eb7d72..e977ab3d6f 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -76,6 +76,13 @@ public: } return w; } + + void clearFocusObject() + { + if (QApplicationPrivate::focus_widget) + QApplicationPrivate::focus_widget->clearFocus(); + } + }; QWidgetWindow::QWidgetWindow(QWidget *widget) -- cgit v1.2.3