diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2017-04-05 11:21:29 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2017-04-14 08:47:53 +0000 |
commit | 1457df74f4c1d770e1e820de8cd082be1bd2489e (patch) | |
tree | 9a6a637ee9304607e0cab1163db9c4c9479f0352 /src/quick/items/qquickitem.cpp | |
parent | 70513c7496dabf504132dd5c900cd85b367bd1b7 (diff) |
Add QQuickItem acceptTouchEvents/setAcceptTouchEvents; require for touch
It has been suboptimal to speculatively deliver touch events to Items
which are not interested; even worse is when we must deliver to a
parent item which is filtering events, when the child Item will not
accept the touch event anyway.
So now it is required that any QQuickItem subclass which wishes to
accept touch events must call setAcceptTouchEvents(true) (typically
in its constructor). If it does not do this, it will not get any
touch events (and this saves us the trouble of looking for parents
which filter touch events, too). It is consistent with needing to
call setAcceptHoverEvents() to get hover events, and
setAcceptedMouseButtons() to get mouse events.
[ChangeLog][QtQuick][QQuickItem] When subclassing QQuickItem, it is
now required to call setAcceptTouchEvents(true) if you need the item
to receive touch events.
Change-Id: Idc76c04f4e7f1d4a613087e756e96dac368f4f23
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/items/qquickitem.cpp')
-rw-r--r-- | src/quick/items/qquickitem.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index bfc4a59851..ef22af965a 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -3172,6 +3172,7 @@ QQuickItemPrivate::QQuickItemPrivate() , antialiasingValid(false) , isTabFence(false) , replayingPressEvent(false) + , touchEnabled(false) , dirtyAttributes(0) , nextDirtyItem(0) , prevDirtyItem(0) @@ -7190,6 +7191,32 @@ void QQuickItem::setAcceptHoverEvents(bool enabled) d->setHasHoverInChild(enabled); } +/*! + Returns whether touch events are accepted by this item. + + The default value is false. + + If this is false, then the item will not receive any touch events through + the touchEvent() function. +*/ +bool QQuickItem::acceptTouchEvents() const +{ + Q_D(const QQuickItem); + return d->touchEnabled; +} + +/*! + If \a enabled is true, this sets the item to accept touch events; + otherwise, touch events are not accepted by this item. + + \sa acceptTouchEvents() +*/ +void QQuickItem::setAcceptTouchEvents(bool accept) +{ + Q_D(QQuickItem); + d->touchEnabled = accept; +} + void QQuickItemPrivate::setHasCursorInChild(bool hasCursor) { #if QT_CONFIG(cursor) |