在Qt QML中。它能够利用​​multitouch​​来做一些我们想做的事情。在今天的文章中。我们将介绍怎样使用multitouch来做一些我们想做的事。


事实上,在QML中利用多点触控是很easy的一件事。我们以下直接来展示我们的例程来给大家解说一下:


import QtQuick 2.0
import Ubuntu.Components 1.1

/*!
\brief MainView with a Label and Button elements.
*/

MainView {
// objectName for functional testing purposes (autopilot-qt5)
objectName: "mainView"

// Note! applicationName needs to match the "name" field of the click manifest
applicationName: "multitouchtest.liu-xiao-guo"

/*
This property enables the application to change orientation
when the device is rotated. The default is false.
*/
//automaticOrientation: true

// Removes the old toolbar and enables new features of the new header.
useDeprecatedToolbar: false

width: units.gu(60)
height: units.gu(85)

Page {
title: i18n.tr("multitouchtest")

MultiPointTouchArea {
anchors.fill: parent
touchPoints: [
TouchPoint { id: point1 },
TouchPoint { id: point2 },
TouchPoint { id: point3 },
TouchPoint { id: point4 }
]
}

Image {
width: parent.width/5
height: parent.height/5
source: "images/image1.jpg"
x: point1.x
y: point1.y
}

Image {
width: parent.width/5
height: parent.height/5
source: "images/image2.jpg"
x: point2.x
y: point2.y
}

Image {
width: parent.width/5
height: parent.height/5
source: "images/image3.jpg"
x: point3.x
y: point3.y
}

Image {
width: parent.width/5
height: parent.height/5
source: "images/image4.jpg"
x: point4.x
y: point4.y
}

}
}



如上面的介绍的那样,我们定义了一个“MultiPointTouchArea”。我们在Image中,绑定它们的坐标和TouchPoint在一起。这样。TouchPoint的坐标变化时,Image能够随时移动。 在它的里面。我们同一时候定义了4个TouchPoint。当我们仅仅有一个手指触屏时,我们能够看见仅仅有image1.jpg能够随着我们的手指移动:


怎样在QML中使用multitouch_ubuntu  怎样在QML中使用multitouch_多点触控_02


当我们同一时候两个手指触屏时。我们能够看到同一时候能够有两个图片image1.jpg及image2.jpg来同一时候移动我们的画面:

怎样在QML中使用multitouch_ico_03


同一时候3个手指触屏时,我们能够看到3个照片同一时候出如今屏幕上。并随我们的手指移动:


怎样在QML中使用multitouch_ico_04


整个项目的源代码在:​​https://github.com/liu-xiao-guo/multitouchtest​