summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@theqtcompany.com>2015-03-23 09:52:08 +0100
committerMichal Klocek <michal.klocek@theqtcompany.com>2015-06-01 06:36:50 +0000
commit6138e25290908372620e9d2ae70893b1b7ae3e08 (patch)
treed05d66e7161bf4df5e0d1585889a956361db4590
parent5430a8345938cb747591a69a8a3785c4ee11cd57 (diff)
downloadqtquickcontrols-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>
-rw-r--r--src/controls/qquickpopupwindow.cpp23
-rw-r--r--src/controls/qquickpopupwindow_p.h11
2 files changed, 29 insertions, 5 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
diff --git a/src/controls/qquickpopupwindow_p.h b/src/controls/qquickpopupwindow_p.h
index 294a84f5..b95275c0 100644
--- a/src/controls/qquickpopupwindow_p.h
+++ b/src/controls/qquickpopupwindow_p.h
@@ -68,11 +68,12 @@ Q_SIGNALS:
void geometryChanged();
protected:
- void mousePressEvent(QMouseEvent *);
- void mouseReleaseEvent(QMouseEvent *);
- void mouseMoveEvent(QMouseEvent *);
- void exposeEvent(QExposeEvent *);
- void hideEvent(QHideEvent *);
+ void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
+ void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE;
+ void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;
+ void exposeEvent(QExposeEvent *) Q_DECL_OVERRIDE;
+ void hideEvent(QHideEvent *) Q_DECL_OVERRIDE;
+ bool event(QEvent *) Q_DECL_OVERRIDE;
virtual bool shouldForwardEventAfterDismiss(QMouseEvent *) const;
protected Q_SLOTS: