diff options
author | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-03-23 09:52:08 +0100 |
---|---|---|
committer | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-06-01 06:36:50 +0000 |
commit | 6138e25290908372620e9d2ae70893b1b7ae3e08 (patch) | |
tree | d05d66e7161bf4df5e0d1585889a956361db4590 /src/controls/qquickpopupwindow.cpp | |
parent | 5430a8345938cb747591a69a8a3785c4ee11cd57 (diff) | |
download | qtquickcontrols-6138e25290908372620e9d2ae70893b1b7ae3e08.tar.gz |
Dismiss a popup window when touch occurs outside
QQuickWindow synthesizes mouse events only for touch points
which occur inside the window. This did not work correctly for
popup windows, which expect a mouse press outside the window
to dismiss the popup.
The workaround is to specifically wait for a TouchBegin outside
the popup to dismiss it.
Task-number: QTBUG-45079
Change-Id: I232220a3fe48c3193299a6a8313a6b9010dd4a53
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'src/controls/qquickpopupwindow.cpp')
-rw-r--r-- | src/controls/qquickpopupwindow.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/controls/qquickpopupwindow.cpp b/src/controls/qquickpopupwindow.cpp index 8db73701..08407e2d 100644 --- a/src/controls/qquickpopupwindow.cpp +++ b/src/controls/qquickpopupwindow.cpp @@ -223,4 +223,27 @@ void QQuickPopupWindow::hideEvent(QHideEvent *e) QQuickWindow::hideEvent(e); } + /*! \reimp */ +bool QQuickPopupWindow::event(QEvent *event) +{ + //QTBUG-45079 + //This is a workaround for popup menu not being closed when using touch input. + //Currently mouse synthesized events are not created for touch events which are + //outside the qquickwindow. + + if (event->type() == QEvent::TouchBegin && !qobject_cast<QQuickPopupWindow*>(transientParent())) { + QRect rect = QRect(QPoint(), size()); + QTouchEvent *touch = static_cast<QTouchEvent*>(event); + QTouchEvent::TouchPoint point = touch->touchPoints().first(); + if ((point.state() == Qt::TouchPointPressed) && !rect.contains(point.pos().toPoint())) { + //first default handling + bool result = QQuickWindow::event(event); + //now specific broken case + if (!m_dismissed) + dismissPopup(); + return result; + } + } + return QQuickWindow::event(event); +} QT_END_NAMESPACE |