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,")")
}
}