如何在QML中使用multitouch

来源:互联网 发布:淘宝批量下架宝贝 编辑:程序博客网 时间:2024/06/05 11:24

在Qt QML中,它可以利用multitouch来做一些我们想做的事情。在今天的文章中,我们将介绍如何使用multitouch来做一些我们想做的事。


其实,在QML中利用多点触控是非常容易的一件事。我们下面直接来展示我们的例程来给大家讲解一下:


import QtQuick 2.0import 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可以随着我们的手指移动:


  


当我们同时两个手指触屏时,我们可以看到同时可以有两个图片image1.jpg及image2.jpg来同时移动我们的画面:



同时3个手指触屏时,我们可以看到3个照片同时出现在屏幕上,并随我们的手指移动:




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


0 0