Qt 4.8
|
The QTouchEvent class contains parameters that describe a touch event. More...
#include <qevent.h>
Classes | |
class | TouchPoint |
The TouchPoint class provides information about a touch point in a QTouchEvent. More... | |
Public Functions | |
QTouchEvent::DeviceType | deviceType () const |
Returns the touch device Type, which is of type QTouchEvent::DeviceType {DeviceType}. More... | |
QTouchEvent (QEvent::Type eventType, QTouchEvent::DeviceType deviceType=TouchScreen, Qt::KeyboardModifiers modifiers=Qt::NoModifier, Qt::TouchPointStates touchPointStates=0, const QList< QTouchEvent::TouchPoint > &touchPoints=QList< QTouchEvent::TouchPoint >()) | |
Constructs a QTouchEvent with the given eventType, deviceType, and touchPoints. More... | |
void | setDeviceType (DeviceType adeviceType) |
Sets the device type to deviceType, which is of type QTouchEvent::DeviceType {DeviceType}. More... | |
void | setTouchPoints (const QList< QTouchEvent::TouchPoint > &atouchPoints) |
Sets the list of touch points for this event. More... | |
void | setTouchPointStates (Qt::TouchPointStates aTouchPointStates) |
Sets a bitwise OR of all the touch point states for this event. More... | |
void | setWidget (QWidget *awidget) |
const QList< QTouchEvent::TouchPoint > & | touchPoints () const |
Returns the list of touch points contained in the touch event. More... | |
Qt::TouchPointStates | touchPointStates () const |
Returns a bitwise OR of all the touch point states for this event. More... | |
QWidget * | widget () const |
Returns the widget on which the event occurred. More... | |
~QTouchEvent () | |
Destroys the QTouchEvent. More... | |
Public Functions inherited from QInputEvent | |
Qt::KeyboardModifiers | modifiers () const |
Returns the keyboard modifier flags that existed immediately before the event occurred. More... | |
QInputEvent (Type type, Qt::KeyboardModifiers modifiers=Qt::NoModifier) | |
void | setModifiers (Qt::KeyboardModifiers amodifiers) |
Sets the keyboard modifiers flags for this event. More... | |
~QInputEvent () | |
Public Functions inherited from QEvent | |
void | accept () |
Sets the accept flag of the event object, the equivalent of calling setAccepted(true). More... | |
void | ignore () |
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false). More... | |
bool | isAccepted () const |
QEvent (Type type) | |
Contructs an event object of type type. More... | |
void | setAccepted (bool accepted) |
bool | spontaneous () const |
Returns true if the event originated outside the application (a system event); otherwise returns false. More... | |
Type | type () const |
Returns the event type. More... | |
virtual | ~QEvent () |
Destroys the event. More... | |
Protected Variables | |
QTouchEvent::DeviceType | _deviceType |
QList< QTouchEvent::TouchPoint > | _touchPoints |
Qt::TouchPointStates | _touchPointStates |
QWidget * | _widget |
Protected Variables inherited from QInputEvent | |
Qt::KeyboardModifiers | modState |
Protected Variables inherited from QEvent | |
QEventPrivate * | d |
ushort | t |
Friends | |
class | QApplication |
class | QApplicationPrivate |
Additional Inherited Members | |
Static Public Functions inherited from QEvent | |
static int | registerEventType (int hint=-1) |
Registers and returns a custom event type. More... | |
The QTouchEvent class contains parameters that describe a touch event.
Touch events occur when pressing, releasing, or moving one or more touch points on a touch device (such as a touch-screen or track-pad). To receive touch events, widgets have to have the Qt::WA_AcceptTouchEvents attribute set and graphics items need to have the acceptTouchEvents attribute set to true.
When using QAbstractScrollArea based widgets, you should enable the Qt::WA_AcceptTouchEvents attribute on the scroll area's viewport.
Similarly to QMouseEvent, Qt automatically grabs each touch point on the first press inside a widget, and the widget will receive all updates for the touch point until it is released. Note that it is possible for a widget to receive events for numerous touch points, and that multiple widgets may be receiving touch events at the same time.
All touch events are of type QEvent::TouchBegin, QEvent::TouchUpdate, or QEvent::TouchEnd. Reimplement QWidget::event() or QAbstractScrollArea::viewportEvent() for widgets and QGraphicsItem::sceneEvent() for items in a graphics view to receive touch events.
The QEvent::TouchUpdate and QEvent::TouchEnd events are sent to the widget or item that accepted the QEvent::TouchBegin event. If the QEvent::TouchBegin event is not accepted and not filtered by an event filter, then no further touch events are sent until the next QEvent::TouchBegin.
The touchPoints() function returns a list of all touch points contained in the event. Information about each touch point can be retrieved using the QTouchEvent::TouchPoint class. The Qt::TouchPointState enum describes the different states that a touch point may have.
By default, QWidget::event() translates the first non-primary touch point in a QTouchEvent into a QMouseEvent. This makes it possible to enable touch events on existing widgets that do not normally handle QTouchEvent. See below for information on some special considerations needed when doing this.
QEvent::TouchBegin is the first touch event sent to a widget. The QEvent::TouchBegin event contains a special accept flag that indicates whether the receiver wants the event. By default, the event is accepted. You should call ignore() if the touch event is not handled by your widget. The QEvent::TouchBegin event is propagated up the parent widget chain until a widget accepts it with accept(), or an event filter consumes it. For QGraphicsItems, the QEvent::TouchBegin event is propagated to items under the mouse (similar to mouse event propagation for QGraphicsItems).
As mentioned above, it is possible that several widgets can be receiving QTouchEvents at the same time. However, Qt makes sure to never send duplicate QEvent::TouchBegin events to the same widget, which could theoretically happen during propagation if, for example, the user touched 2 separate widgets in a QGroupBox and both widgets ignored the QEvent::TouchBegin event.
To avoid this, Qt will group new touch points together using the following rules:
When the first touch point is detected, the destination widget is determined firstly by the location on screen and secondly by the propagation rules.
When additional touch points are detected, Qt first looks to see if there are any active touch points on any ancestor or descendent of the widget under the new touch point. If there are, the new touch point is grouped with the first, and the new touch point will be sent in a single QTouchEvent to the widget that handled the first touch point. (The widget under the new touch point will not receive an event).
This makes it possible for sibling widgets to handle touch events independently while making sure that the sequence of QTouchEvents is always correct.
QTouchEvent delivery is independent from that of QMouseEvent. On some windowing systems, mouse events are also sent for the primary touch point. This means it is possible for your widget to receive both QTouchEvent and QMouseEvent for the same user interaction point. You can use the QTouchEvent::TouchPoint::isPrimary() function to identify the primary touch point.
Note that on some systems, it is possible to receive touch events without a primary touch point. All this means is that there will be no mouse event generated for the touch points in the QTouchEvent.
As mentioned above, enabling touch events means multiple widgets can be receiving touch events simultaneously. Combined with the default QWidget::event() handling for QTouchEvents, this gives you great flexibility in designing touch user interfaces. Be aware of the implications. For example, it is possible that the user is moving a QSlider with one finger and pressing a QPushButton with another. The signals emitted by these widgets will be interleaved.
Recursion into the event loop using one of the exec() methods (e.g., QDialog::exec() or QMenu::exec()) in a QTouchEvent event handler is not supported. Since there are multiple event recipients, recursion may cause problems, including but not limited to lost events and unexpected infinite recursion.
QTouchEvents are not affected by a mouse grab or an active pop-up widget. The behavior of QTouchEvents is undefined when opening a pop-up or grabbing the mouse while there are more than one active touch points.
This enum represents the type of device that generated a QTouchEvent.
Enumerator | |
---|---|
TouchScreen | |
TouchPad |
Definition at line 805 of file qevent.h.
QTouchEvent::QTouchEvent | ( | QEvent::Type | eventType, |
QTouchEvent::DeviceType | deviceType = TouchScreen , |
||
Qt::KeyboardModifiers | modifiers = Qt::NoModifier , |
||
Qt::TouchPointStates | touchPointStates = 0 , |
||
const QList< QTouchEvent::TouchPoint > & | touchPoints = QList<QTouchEvent::TouchPoint>() |
||
) |
Constructs a QTouchEvent with the given eventType, deviceType, and touchPoints.
The touchPointStates and modifiers are the current touch point states and keyboard modifiers at the time of the event.
Definition at line 4307 of file qevent.cpp.
QTouchEvent::~QTouchEvent | ( | ) |
|
inline |
Returns the touch device Type, which is of type QTouchEvent::DeviceType {DeviceType}.
Definition at line 818 of file qevent.h.
Referenced by QWidget::event(), and QGraphicsScenePrivate::touchEventHandler().
|
inline |
Sets the device type to deviceType, which is of type QTouchEvent::DeviceType {DeviceType}.
Definition at line 824 of file qevent.h.
|
inline |
Sets the list of touch points for this event.
Definition at line 826 of file qevent.h.
Referenced by QGraphicsViewPrivate::translateTouchEvent(), and QGraphicsScenePrivate::updateTouchPointsForItem().
|
inline |
|
inline |
Sets the widget for this event.
Definition at line 823 of file qevent.h.
Referenced by QApplication::notify(), and QGraphicsView::viewportEvent().
|
inline |
Returns the list of touch points contained in the touch event.
Definition at line 820 of file qevent.h.
Referenced by QDeclarativePinchArea::event(), QWidget::event(), QApplication::notify(), QPanGestureRecognizer::recognize(), QPinchGestureRecognizer::recognize(), QSwipeGestureRecognizer::recognize(), QTapGestureRecognizer::recognize(), QTapAndHoldGestureRecognizer::recognize(), QMacPinchGestureRecognizer::reset(), QDeclarativePinchArea::sceneEventFilter(), QGraphicsScenePrivate::sendTouchBeginEvent(), QGraphicsScenePrivate::touchEventHandler(), QGraphicsViewPrivate::translateTouchEvent(), QGraphicsScenePrivate::updateTouchPointsForItem(), and QApplicationPrivate::updateTouchPointsForWidget().
|
inline |
Returns a bitwise OR of all the touch point states for this event.
Definition at line 819 of file qevent.h.
Referenced by QSwipeGestureRecognizer::recognize().
|
inline |
Returns the widget on which the event occurred.
Definition at line 817 of file qevent.h.
Referenced by QGraphicsScenePrivate::sendTouchBeginEvent(), QGraphicsScenePrivate::touchEventHandler(), and QGraphicsScenePrivate::updateTouchPointsForItem().
|
friend |
|
friend |
|
protected |
|
protected |
Definition at line 832 of file qevent.h.
Referenced by QApplication::notify(), and QApplicationPrivate::updateTouchPointsForWidget().
|
protected |