QTouchEvent class contains parameters that describe a touch event. 更多...
头: | #include <QTouchEvent> |
qmake: | QT += gui |
Since: | Qt 4.6 |
继承: | QInputEvent |
class | TouchPoint |
QTouchEvent (QEvent::Type eventType , QTouchDevice * device = Q_NULLPTR, Qt::KeyboardModifiers modifiers = Qt::NoModifier, Qt::TouchPointStates touchPointStates = Qt::TouchPointStates(), const QList<QTouchEvent::TouchPoint> & touchPoints = QList<QTouchEvent::TouchPoint> ()) | |
~QTouchEvent () | |
QTouchDevice * | device () const |
QObject * | target () const |
Qt::TouchPointStates | touchPointStates () const |
const QList<QTouchEvent::TouchPoint> & | touchPoints () const |
QWindow * | window () const |
QTouchEvent class contains parameters that describe a touch event.
触摸事件发生,当在触摸设备 (譬如:触摸屏或跟踪板) 中按下、释放或移动一个或多个触摸点时。要接收触摸事件,Widget 必须拥有 Qt::WA_AcceptTouchEvents 属性设置和图形项需要拥有 acceptTouchEvents 属性设置为 true。
当使用 QAbstractScrollArea 基 Widget,应启用 Qt::WA_AcceptTouchEvents 属性在卷动区域 viewport .
类似于 QMouseEvent ,Qt 自动抓取每个触摸点当在 Widget 内第一次按下时,且小部件将接收触摸点的所有更新,直到它被释放。注意,Widget 能接收很多触摸点事件,且多个小部件可能同时接收触摸事件。
所有触摸事件类型,包括 QEvent::TouchBegin , QEvent::TouchUpdate , QEvent::TouchEnd or QEvent::TouchCancel 。重实现 QWidget::event () 或 QAbstractScrollArea::viewportEvent () 对于 Widget 和 QGraphicsItem::sceneEvent () 对于要接收触摸事件的图形视图项。
不像 Widget,QWindows 始终接收触摸事件,无需选项。当直接工作于 QWindow ,是足够的重实现 QWindow::touchEvent ().
QEvent::TouchUpdate and QEvent::TouchEnd 事件会被发送给 Widget 或项接受 QEvent::TouchBegin 事件。若 QEvent::TouchBegin 事件未接受且未被事件过滤器所过滤,则进一步触摸事件不会被发送直到下一 QEvent::TouchBegin .
某些系统可能发送事件类型 QEvent::TouchCancel . Upon receiving this event applications are requested to ignore the entire active touch sequence. For example in a composited system the compositor may decide to treat certain gestures as system-wide gestures. Whenever such a decision is made (the gesture is recognized), the clients will be notified with a QEvent::TouchCancel event so they can update their state accordingly.
touchPoints () function returns a list of all touch points contained in the event. Note that this list may be empty, for example in case of a QEvent::TouchCancel event. Information about each touch point can be retrieved using the QTouchEvent::TouchPoint 类。 Qt::TouchPointState enum describes the different states that a touch point may have.
注意: The list of touchPoints () will never be partial: A touch event will always contain a touch point for each existing physical touch contacts targetting the window or widget to which the event is sent. For instance, assuming that all touches target the same window or widget, an event with a condition of touchPoints ().count()==2 is guaranteed to imply that the number of fingers touching the touchscreen or touchpad is exactly two.
默认情况下, QGuiApplication translates the first touch point in a QTouchEvent 成 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 是发送给 Widget 的第一个触摸事件。 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 事件。
为避免这,Qt 将使用以下规则将新的接触点分组在一起:
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 。应用程序标志 Qt::AA_SynthesizeTouchForUnhandledMouseEvents and Qt::AA_SynthesizeMouseForUnhandledTouchEvents 可以用于启用 (或禁用) 将触摸事件自动合成为鼠标事件,和将鼠标事件自动合成为触摸事件。
另请参阅 QTouchEvent::TouchPoint , Qt::TouchPointState , Qt::WA_AcceptTouchEvents ,和 QGraphicsItem::acceptTouchEvents ().
构造 QTouchEvent 采用给定 eventType , device ,和 touchPoints 。 touchPointStates and modifiers are the current touch point states and keyboard modifiers at the time of the event.
销毁 QTouchEvent .
Returns the touch device from which this touch event originates.
Returns the target object within the window on which the event occurred. This is typically a QWidget 或 QQuickItem 。可能为 0 当没有可用特定目标时。
返回此事件所有触摸点状态的按位 OR。
Returns the list of touch points contained in the touch event.
Returns the window on which the event occurred. Useful for doing global-local mapping on data like rawScreenPositions() which, for performance reasons, only stores the global positions in the touch event.