summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@digia.com>2014-11-04 11:47:50 +0100
committerShawn Rutledge <shawn.rutledge@digia.com>2014-12-08 09:56:25 +0100
commit370d421495a200860c9fb583b526dcf8bf8145fb (patch)
treeae86f9edf7c668045c480dd31d31384b7d22664f /src
parentaca0fb17862875209a234f0384b981efe831f4b6 (diff)
Widgets: be more careful when setting focus on touch release
An application might choose to change focus when receiving mouse/touch press/move events. This is in conflict with Qt assigning focus on touch release (QPlatformIntegration::SetFocusOnTouchRelease), since Qt might then reassign focus to something else. An example of this is seen with the "frozencolumn" example. Here, when the user double clicks on a cell, the application creates an 'edit' widget inside the cell that gets focus. But at soon as the last release is sent, Qt will change focus to the focus proxy of QScrollArea instead. This patch will introduce an exception to setting focus on release, so that we only set focus if we detect that focus didn't change (by the app) while processing press/move events. Task-number: QTBUG-39390 Change-Id: I7b398b59e3175265afd2fcd938e11f88155abc89 Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/kernel/qapplication.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index 269fe452c1..b7d0869289 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -4172,11 +4172,13 @@ void QApplicationPrivate::giveFocusAccordingToFocusPolicy(QWidget *widget, QEven
{
const bool setFocusOnRelease = QGuiApplication::styleHints()->setFocusOnTouchRelease();
Qt::FocusPolicy focusPolicy = Qt::ClickFocus;
+ static QPointer<QWidget> focusedWidgetOnTouchBegin = 0;
switch (event->type()) {
case QEvent::MouseButtonPress:
case QEvent::MouseButtonDblClick:
case QEvent::TouchBegin:
+ focusedWidgetOnTouchBegin = QApplication::focusWidget();
if (setFocusOnRelease)
return;
break;
@@ -4184,6 +4186,11 @@ void QApplicationPrivate::giveFocusAccordingToFocusPolicy(QWidget *widget, QEven
case QEvent::TouchEnd:
if (!setFocusOnRelease)
return;
+ if (focusedWidgetOnTouchBegin != QApplication::focusWidget()) {
+ // Focus widget was changed while delivering press/move events.
+ // To not interfere with application logic, we leave focus as-is
+ return;
+ }
break;
case QEvent::Wheel:
focusPolicy = Qt::WheelFocus;