diff options
authorRichard Moe Gustavsen <>2013-10-29 23:10:15 +0100
committerThe Qt Project <>2013-10-31 23:37:54 +0100
commitcfa85c76c7c7e1622cb02edcbbc3d948edca1e7f (patch)
parenta1bc2921a44409736a8b8576243a0c9129d7683b (diff)
QWindowPrivate: add virtual function 'clearFocusObject'
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 <>
3 files changed, 13 insertions, 0 deletions
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)