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。