QML手勢相關的實驗模塊:Qt.labs.gestures模塊介紹

一、QtQuick 1 vs QtQuick2

兩者仍是有很大區別的,不管從模塊重組仍是從底層實現,均需注意。下面是兩個官方文檔給出的差異說明及列表:html

  1. 差異說明
  2. 差異列表

二、Qt.labs.gestures

  • 雖然沒有正式的Release模塊(Types in the Qt.labs module are not guaranteed to remain compatible in future versions.),但在qt4.8中,提供了一個gesture特性的試驗模塊git

  • 此外,還有一個開發者寫的非官方文檔可供瞭解gesture模塊開發的背景及主要接口、屬性及函數:Getting in touch with Qt Quick: Gestures and QML函數

  • 但,咱們依然要注意,在qt文檔中給出以下說明: Warning: GestureArea is an experimental element whose development has been discontinued. PinchArea is available in QtQuick 1.1 and handles two finger gesture input. Note: This element is only functional on devices with touch input.ui

  • 此外,附上一個git網址,裏面全是Qt libs特性的實驗項目,你能夠找到本身須要的模塊。不過有一些項目已經好久沒有更新了。例如這裏討論的gestures。 因此,在實際項目中,須要權衡一下,或者找到替代方案!!!code

  • 實驗特性實現文件在qt5當中的路徑爲:xxx/qt5.3.1/qtbase/qml/Qt/labs。 目前只有2個內置特性模塊:settings和folderlistmodel。orm

  • 另外:Qt Sensor Gestures也有與手勢相關的傳感器的內容。htm

  • 在qt5.3中的開發文檔中,亦有相關的demo,路徑爲:xxx/qt5.3.1/qtquick1/examples/declarative/touchinteraction。 目錄下面有3個例子:一個是關於gesture的,一個是鼠標域(MouseArea)的,一個是彈碰域(PinchArea)的。blog

三、官方demo

<!-- lang: js -->
import QtQuick 1.0
import Qt.labs.gestures 1.0

// Only works on platforms with Touch support.

Rectangle {
id: rect
width: 320
height: 180

Text {
    anchors.centerIn: parent
    text: "Tap / TapAndHold / Pan / Pinch / Swipe\nOnly works on platforms with Touch support."
    horizontalAlignment: Text.Center
}

GestureArea {
    anchors.fill: parent
    focus: true

    // Only some of the many gesture properties are shown. See Gesture documentation.

    onTap:
        console.log("tap pos = (",gesture.position.x,",",gesture.position.y,")")
    onTapAndHold:
        console.log("tap and hold pos = (",gesture.position.x,",",gesture.position.y,")")
    onPan:
        console.log("pan delta = (",gesture.delta.x,",",gesture.delta.y,") acceleration = ",gesture.acceleration)
    onPinch:
        console.log("pinch center = (",gesture.centerPoint.x,",",gesture.centerPoint.y,") rotation =",gesture.rotationAngle," scale =",gesture.scaleFactor)
    onSwipe:
        console.log("swipe angle=",gesture.swipeAngle)
    onGesture:
        console.log("gesture hot spot = (",gesture.hotSpot.x,",",gesture.hotSpot.y,")")
}
}
相關文章
相關標籤/搜索