Qt 4.8
Classes | Public Types | Public Functions | Protected Variables | Friends | List of all members
QTouchEvent Class Reference

The QTouchEvent class contains parameters that describe a touch event. More...

#include <qevent.h>

Inheritance diagram for QTouchEvent:
QInputEvent QEvent

Classes

class  TouchPoint
 The TouchPoint class provides information about a touch point in a QTouchEvent. More...
 

Public Types

enum  DeviceType { TouchScreen, TouchPad }
 This enum represents the type of device that generated a QTouchEvent. More...
 
- Public Types inherited from QEvent
enum  Type {
  None = 0, Timer = 1, MouseButtonPress = 2, MouseButtonRelease = 3,
  MouseButtonDblClick = 4, MouseMove = 5, KeyPress = 6, KeyRelease = 7,
  FocusIn = 8, FocusOut = 9, Enter = 10, Leave = 11,
  Paint = 12, Move = 13, Resize = 14, Create = 15,
  Destroy = 16, Show = 17, Hide = 18, Close = 19,
  Quit = 20, ParentChange = 21, ParentAboutToChange = 131, ThreadChange = 22,
  WindowActivate = 24, WindowDeactivate = 25, ShowToParent = 26, HideToParent = 27,
  Wheel = 31, WindowTitleChange = 33, WindowIconChange = 34, ApplicationWindowIconChange = 35,
  ApplicationFontChange = 36, ApplicationLayoutDirectionChange = 37, ApplicationPaletteChange = 38, PaletteChange = 39,
  Clipboard = 40, Speech = 42, MetaCall = 43, SockAct = 50,
  WinEventAct = 132, DeferredDelete = 52, DragEnter = 60, DragMove = 61,
  DragLeave = 62, Drop = 63, DragResponse = 64, ChildAdded = 68,
  ChildPolished = 69, ChildRemoved = 71, ShowWindowRequest = 73, PolishRequest = 74,
  Polish = 75, LayoutRequest = 76, UpdateRequest = 77, UpdateLater = 78,
  EmbeddingControl = 79, ActivateControl = 80, DeactivateControl = 81, ContextMenu = 82,
  InputMethod = 83, AccessibilityPrepare = 86, TabletMove = 87, LocaleChange = 88,
  LanguageChange = 89, LayoutDirectionChange = 90, Style = 91, TabletPress = 92,
  TabletRelease = 93, OkRequest = 94, HelpRequest = 95, IconDrag = 96,
  FontChange = 97, EnabledChange = 98, ActivationChange = 99, StyleChange = 100,
  IconTextChange = 101, ModifiedChange = 102, MouseTrackingChange = 109, WindowBlocked = 103,
  WindowUnblocked = 104, WindowStateChange = 105, ToolTip = 110, WhatsThis = 111,
  StatusTip = 112, ActionChanged = 113, ActionAdded = 114, ActionRemoved = 115,
  FileOpen = 116, Shortcut = 117, ShortcutOverride = 51, WhatsThisClicked = 118,
  ToolBarChange = 120, ApplicationActivate = 121, ApplicationActivated = ApplicationActivate, ApplicationDeactivate = 122,
  ApplicationDeactivated = ApplicationDeactivate, QueryWhatsThis = 123, EnterWhatsThisMode = 124, LeaveWhatsThisMode = 125,
  ZOrderChange = 126, HoverEnter = 127, HoverLeave = 128, HoverMove = 129,
  AccessibilityHelp = 119, AccessibilityDescription = 130, AcceptDropsChange = 152, MenubarUpdated = 153,
  ZeroTimerEvent = 154, GraphicsSceneMouseMove = 155, GraphicsSceneMousePress = 156, GraphicsSceneMouseRelease = 157,
  GraphicsSceneMouseDoubleClick = 158, GraphicsSceneContextMenu = 159, GraphicsSceneHoverEnter = 160, GraphicsSceneHoverMove = 161,
  GraphicsSceneHoverLeave = 162, GraphicsSceneHelp = 163, GraphicsSceneDragEnter = 164, GraphicsSceneDragMove = 165,
  GraphicsSceneDragLeave = 166, GraphicsSceneDrop = 167, GraphicsSceneWheel = 168, KeyboardLayoutChange = 169,
  DynamicPropertyChange = 170, TabletEnterProximity = 171, TabletLeaveProximity = 172, NonClientAreaMouseMove = 173,
  NonClientAreaMouseButtonPress = 174, NonClientAreaMouseButtonRelease = 175, NonClientAreaMouseButtonDblClick = 176, MacSizeChange = 177,
  ContentsRectChange = 178, MacGLWindowChange = 179, FutureCallOut = 180, GraphicsSceneResize = 181,
  GraphicsSceneMove = 182, CursorChange = 183, ToolTipChange = 184, NetworkReplyUpdated = 185,
  GrabMouse = 186, UngrabMouse = 187, GrabKeyboard = 188, UngrabKeyboard = 189,
  MacGLClearDrawable = 191, StateMachineSignal = 192, StateMachineWrapped = 193, TouchBegin = 194,
  TouchUpdate = 195, TouchEnd = 196, NativeGesture = 197, RequestSoftwareInputPanel = 199,
  CloseSoftwareInputPanel = 200, UpdateSoftKeys = 201, WinIdChange = 203, Gesture = 198,
  GestureOverride = 202, PlatformPanel = 212, User = 1000, MaxUser = 65535
}
 This enum type defines the valid event types in Qt. 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...
 
QWidgetwidget () 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...
 

Detailed Description

The QTouchEvent class contains parameters that describe a touch event.

Since
4.6

Enabling Touch Events

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.

Event Handling

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.

Event Delivery and Propagation

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).

Touch Point Grouping

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:

This makes it possible for sibling widgets to handle touch events independently while making sure that the sequence of QTouchEvents is always correct.

Mouse Events and the Primary Touch Point

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.

Caveats

See also
QTouchEvent::TouchPoint, Qt::TouchPointState, Qt::WA_AcceptTouchEvents, QGraphicsItem::acceptTouchEvents()

Definition at line 741 of file qevent.h.

Enumerations

◆ DeviceType

This enum represents the type of device that generated a QTouchEvent.

  • TouchScreen In this type of device, the touch surface and display are integrated. This means the surface and display typically have the same size, such that there is a direct relationship between the touch points' physical positions and the coordinate reported by QTouchEvent::TouchPoint. As a result, Qt allows the user to interact directly with multiple QWidgets and QGraphicsItems at the same time.
  • TouchPad In this type of device, the touch surface is separate from the display. There is not a direct relationship between the physical touch location and the on-screen coordinates. Instead, they are calculated relative to the current mouse position, and the user must use the touch-pad to move this reference point. Unlike touch-screens, Qt allows users to only interact with a single QWidget or QGraphicsItem at a time.
Enumerator
TouchScreen 
TouchPad 

Definition at line 805 of file qevent.h.

Constructors and Destructors

◆ QTouchEvent()

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.

4312  : QInputEvent(eventType, modifiers),
4313  _widget(0),
4316  _touchPoints(touchPoints)
4317 { }
QTouchEvent::DeviceType _deviceType
Definition: qevent.h:830
Qt::TouchPointStates _touchPointStates
Definition: qevent.h:831
QList< QTouchEvent::TouchPoint > _touchPoints
Definition: qevent.h:832
QTouchEvent::DeviceType deviceType() const
Returns the touch device Type, which is of type QTouchEvent::DeviceType {DeviceType}.
Definition: qevent.h:818
Qt::TouchPointStates touchPointStates() const
Returns a bitwise OR of all the touch point states for this event.
Definition: qevent.h:819
QInputEvent(Type type, Qt::KeyboardModifiers modifiers=Qt::NoModifier)
Definition: qevent.cpp:77
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately before the event occurred.
Definition: qevent.h:79
QWidget * _widget
Definition: qevent.h:829

◆ ~QTouchEvent()

QTouchEvent::~QTouchEvent ( )

Destroys the QTouchEvent.

Definition at line 4322 of file qevent.cpp.

4323 { }

Functions

◆ deviceType()

QTouchEvent::DeviceType QTouchEvent::deviceType ( ) const
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().

818 { return _deviceType; }
QTouchEvent::DeviceType _deviceType
Definition: qevent.h:830

◆ setDeviceType()

void QTouchEvent::setDeviceType ( DeviceType  deviceType)
inline

Sets the device type to deviceType, which is of type QTouchEvent::DeviceType {DeviceType}.

Warning
This function is not part of the public interface.

Definition at line 824 of file qevent.h.

824 { _deviceType = adeviceType; }
QTouchEvent::DeviceType _deviceType
Definition: qevent.h:830

◆ setTouchPoints()

void QTouchEvent::setTouchPoints ( const QList< QTouchEvent::TouchPoint > &  touchPoints)
inline

Sets the list of touch points for this event.

Warning
This function is not part of the public interface.

Definition at line 826 of file qevent.h.

Referenced by QGraphicsViewPrivate::translateTouchEvent(), and QGraphicsScenePrivate::updateTouchPointsForItem().

826 { _touchPoints = atouchPoints; }
QList< QTouchEvent::TouchPoint > _touchPoints
Definition: qevent.h:832

◆ setTouchPointStates()

void QTouchEvent::setTouchPointStates ( Qt::TouchPointStates  touchPointStates)
inline

Sets a bitwise OR of all the touch point states for this event.

Warning
This function is not part of the public interface.

Definition at line 825 of file qevent.h.

825 { _touchPointStates = aTouchPointStates; }
Qt::TouchPointStates _touchPointStates
Definition: qevent.h:831

◆ setWidget()

void QTouchEvent::setWidget ( QWidget widget)
inline
Warning
This function is not part of the public interface.

Sets the widget for this event.

Definition at line 823 of file qevent.h.

Referenced by QApplication::notify(), and QGraphicsView::viewportEvent().

823 { _widget = awidget; }
QWidget * _widget
Definition: qevent.h:829

◆ touchPoints()

const QList< QTouchEvent::TouchPoint > & QTouchEvent::touchPoints ( ) const
inline

◆ touchPointStates()

Qt::TouchPointStates QTouchEvent::touchPointStates ( ) const
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().

819 { return _touchPointStates; }
Qt::TouchPointStates _touchPointStates
Definition: qevent.h:831

◆ widget()

QWidget * QTouchEvent::widget ( ) const
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().

817 { return _widget; }
QWidget * _widget
Definition: qevent.h:829

Friends and Related Functions

◆ QApplication

friend class QApplication
friend

Definition at line 834 of file qevent.h.

◆ QApplicationPrivate

friend class QApplicationPrivate
friend

Definition at line 835 of file qevent.h.

Properties

◆ _deviceType

QTouchEvent::DeviceType QTouchEvent::_deviceType
protected

Definition at line 830 of file qevent.h.

◆ _touchPoints

QList<QTouchEvent::TouchPoint> QTouchEvent::_touchPoints
protected

◆ _touchPointStates

Qt::TouchPointStates QTouchEvent::_touchPointStates
protected

Definition at line 831 of file qevent.h.

◆ _widget

QWidget* QTouchEvent::_widget
protected

Definition at line 829 of file qevent.h.


The documentation for this class was generated from the following files: