QTouchEvent 類

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 首先由屏幕位置確定,其次由傳播規則確定。
  • 當檢測到其它觸摸點時,Qt 首先查看新觸摸點下 Widget 的任何祖先 (或後代) 中是否有任何活動觸摸點。若有,分組新觸摸點與第一觸摸點,並發送新觸摸點按單 QTouchEvent 到處理第一觸摸點的 Widget (新觸摸點下的小部件不接收事件)。

這使同級 Widget 能夠獨立處理觸摸事件,同時確保 QTouchEvents 序列始終正確成為可能。

Mouse Events and the Primary Touch Point

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 .

告誡

  • 如上所述,啓用觸摸事件意味著多個 Widget 可以同時接收觸摸事件。組閤默認 QWidget::event () 處理 QTouchEvents,這為設計觸摸用戶界麵賦予瞭很大靈活性。要意識到其中所隱含的。例如,用戶可能正移動 QSlider 用一根手指並按下 QPushButton 用另一根手指。由這些 Widget 發射的信號將交錯。
  • 遞歸到事件循環使用某一 exec() 方法 (如 QDialog::exec () 或 QMenu::exec ()) 在 QTouchEvent 事件處理程序不支持。由於存在多個事件收件人,遞歸可能導緻問題,包括但不限於丟失事件和意外無限遞歸。
  • QTouchEvents 不受影響被 鼠標抓取 活動彈齣 Widget 。QTouchEvents 的行為未定義,當打開彈齣窗口 (或抓取鼠標) 且存在多個活動觸摸點時。

另請參閱 QTouchEvent::TouchPoint , Qt::TouchPointState , Qt::WA_AcceptTouchEvents ,和 QGraphicsItem::acceptTouchEvents ().

成員類型文檔編製

enum QTouchEvent:: DeviceType

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:: 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 采用給定 eventType , deviceType ,和 touchPoints touchPointStates and modifiers 是事件發生時當前觸摸點狀態和鍵盤修飾符。

QTouchEvent:: ~QTouchEvent ()

銷毀 QTouchEvent .

QTouchEvent::DeviceType QTouchEvent:: deviceType () const

Returns the touch device Type, which is of type DeviceType .

Qt::TouchPointStates QTouchEvent:: touchPointStates () const

返迴此事件所有觸摸點狀態的按位 OR。

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

返迴觸摸事件中包含的觸摸點列錶。

QWidget * QTouchEvent:: widget () const

返迴事件在其中發生的 Widget。