The QTouchEvent 类包含触摸事件的描述参数。 更多...
| 头: | #include <QTouchEvent> |
| Since: | Qt 4.6 |
| 继承: | QInputEvent |
| class | TouchPoint |
| enum | DeviceType { TouchScreen, TouchPad } |
| 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> ()) | |
| ~QTouchEvent () | |
| QTouchEvent::DeviceType | deviceType () const |
| Qt::TouchPointStates | touchPointStates () const |
| const QList<QTouchEvent::TouchPoint> & | touchPoints () const |
| QWidget * | widget () const |
The QTouchEvent 类包含触摸事件的描述参数。
触摸事件发生,当在触摸设备 (譬如:触摸屏或跟踪板) 中按下、释放或移动一个或多个触摸点时。要接收触摸事件,Widget 必须拥有 Qt::WA_AcceptTouchEvents 属性设置和图形项需要拥有 acceptTouchEvents 属性设置为 true。
当使用 QAbstractScrollArea 基 Widget,应启用 Qt::WA_AcceptTouchEvents 属性在卷动区域 viewport .
类似于 QMouseEvent ,Qt 自动抓取每个触摸点当在 Widget 内第一次按下时,且小部件将接收触摸点的所有更新,直到它被释放。注意,Widget 能接收很多触摸点事件,且多个小部件可能同时接收触摸事件。
所有触摸事件类型,包括 QEvent::TouchBegin , QEvent::TouchUpdate ,或 QEvent::TouchEnd 。重实现 QWidget::event () 或 QAbstractScrollArea::viewportEvent () 对于 Widget 和 QGraphicsItem::sceneEvent () 对于要接收触摸事件的图形视图项。
The QEvent::TouchUpdate and QEvent::TouchEnd 事件会被发送给 Widget 或项接受 QEvent::TouchBegin 事件。若 QEvent::TouchBegin 事件未接受且未被事件过滤器所过滤,则进一步触摸事件不会被发送直到下一 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 类。 Qt::TouchPointState 枚举描述触摸点可能拥有的不同状态。
默认情况下, QWidget::event () translates the first non-primary touch point in a QTouchEvent 成 QMouseEvent 。这使启用触摸事件成为可能,当现有 Widget 通常不处理 QTouchEvent 。见下文,了解某些需要特殊注意事项的有关信息,当这样做时。
QEvent::TouchBegin 是发送给 Widget 的第一触摸事件。 QEvent::TouchBegin 事件包含指示接收者是否想要事件的特殊接受标志。默认情况下,接受事件。应该调用 ignore () 若 Widget 不处理触摸事件。 QEvent::TouchBegin 事件会沿父级 Widget 链向上传播,直到小部件接受它采用 accept (),或事件过滤器消耗掉它。对于 QGraphicsItems, QEvent::TouchBegin 事件被传播给鼠标下项 (类似于 QGraphicsItems 的鼠标事件传播)。
如上所述,它是可能的几个 Widget 可以同时接收 QTouchEvents。不管怎样,Qt 确保从不重复发送 QEvent::TouchBegin 事件给同一 Widget,理论上传播期间可能发生,例如,若用户触摸 2 单独 Widget 在 QGroupBox 与两 Widget 忽略 QEvent::TouchBegin 事件。
为避免这,Qt 使用下列规则将新触摸点分组到一起:
这使同级 Widget 能够独立处理触摸事件,同时确保 QTouchEvents 序列始终正确成为可能。
QTouchEvent 的交付独立于 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 .
另请参阅 QTouchEvent::TouchPoint , Qt::TouchPointState , Qt::WA_AcceptTouchEvents ,和 QGraphicsItem::acceptTouchEvents ().
This enum represents the type of device that generated a QTouchEvent .
| 常量 | 值 | 描述 |
|---|---|---|
QTouchEvent::TouchScreen
|
0
|
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. |
QTouchEvent::TouchPad
|
1
|
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. |
构造 QTouchEvent 采用给定 eventType , deviceType ,和 touchPoints 。 touchPointStates and modifiers 是事件发生时当前触摸点状态和键盘修饰符。
销毁 QTouchEvent .
Returns the touch device Type, which is of type DeviceType .
返回此事件所有触摸点状态的按位 OR。
返回触摸事件中包含的触摸点列表。
返回事件在其中发生的 Widget。