Qt 多点触摸区域和画布

Qt 多点触摸区域和画布,qt,qml,qt-quick,Qt,Qml,Qt Quick,我正在Canvas组件中玩MultiPointTouchArea,做一些绘图练习。下面的代码可以工作,但是onReleased事件被调用了两次,我不明白为什么 从下面的日志语句中,我看到它首先使用一个接触点调用,然后再次使用两个接触点——x和y位置对所有人都是相同的。这些接触点的id也未定义 我不明白。由于我定义了一个最大接触点,并且只需一次触摸即可进行测试(我正在笔记本电脑上使用触摸板,只用一个“手指”进行测试): 为什么我有多个接触点 为什么onrelease会被调用两次 既然我已经定义了

我正在
Canvas
组件中玩
MultiPointTouchArea
,做一些绘图练习。下面的代码可以工作,但是
onReleased
事件被调用了两次,我不明白为什么

从下面的日志语句中,我看到它首先使用一个
接触点
调用,然后再次使用两个
接触点
——x和y位置对所有人都是相同的。这些接触点的
id
也未定义

我不明白。由于我定义了一个
最大接触点
,并且只需一次触摸即可进行测试(我正在笔记本电脑上使用触摸板,只用一个“手指”进行测试):

  • 为什么我有多个接触点
  • 为什么
    onrelease
    会被调用两次
  • 既然我已经定义了我的接触点,为什么接触点
    id
    没有定义


导入QtQuick 2.5
导入QtQuick.Controls 1.4
应用程序窗口{
可见:正确
宽度:640
身高:480
标题:qsTr(“画布”)
帆布{
id:画布
锚定。填充:父级
不动产lastX:0
不动产更新:0
onPaint:{
var ctx=getContext(“2d”)
ctx.lineWidth=1
ctx.strokeStyle=“蓝色”
ctx.beginPath()
ctx.moveTo(lastX,lastY)
ctx.lineTo(触摸1.x,触摸1.y)
ctx.stroke()
canvas.lastX=touch1.x;
canvas.lastY=touch1.y;
}
函数clearCanvas(){
var ctx=canvas.getContext(“2d”)
clearRect(0,0,canvas.width,canvas.height)
}
多点接触区{
锚定。填充:父级
最低接触点:1
最大接触点:1
接触点:[接触点{id:touch1}]
按下按钮:{
canvas.lastX=touch1.x;
canvas.lastY=touch1.y;
canvas.clearCanvas();
}
发布日期:{
console.log(“released”,touchPoints.length);//调用两次?
var-tp;
对于(变量i=0;i
因此,这些问题似乎存在公开的bug

“两次发布事件”问题已报告,目前尚未解决:

“没有以前的,以前的”接触点问题也存在:

qml: released 1
qml:     undefined 386.66015625 207.6640625
qml: is this touch1? true

qml: released 2
qml:     undefined 386.66015625 207.6640625
qml: is this touch1? true
qml:     undefined 386.66015625 207.6640625
qml: is this touch1? true
import QtQuick 2.5
import QtQuick.Controls 1.4

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Canvas")

    Canvas {
        id: canvas
        anchors.fill: parent

        property real lastX: 0
        property real lastY: 0

        onPaint: {
            var ctx = getContext("2d")
            ctx.lineWidth = 1
            ctx.strokeStyle = "blue"
            ctx.beginPath()
            ctx.moveTo(lastX,lastY)
            ctx.lineTo(touch1.x,touch1.y)
            ctx.stroke()

            canvas.lastX = touch1.x;
            canvas.lastY = touch1.y;
        }

        function clearCanvas() {
            var ctx = canvas.getContext("2d")
             ctx.clearRect(0, 0, canvas.width, canvas.height)
        }

        MultiPointTouchArea {
            anchors.fill: parent
            minimumTouchPoints: 1
            maximumTouchPoints: 1
            touchPoints: [TouchPoint { id: touch1 }]

            onPressed: {
                canvas.lastX = touch1.x;
                canvas.lastY = touch1.y;

                canvas.clearCanvas();
            }

            onReleased: {

                console.log("released", touchPoints.length); // CALLED TWICE?

                var tp;
                for (var i = 0; i < touchPoints.length; i++) {
                tp = touchPoints[i];
                    console.log("\t",tp.id, tp.x, tp.y);

                    console.log("is this touch1?", tp === touch1);
                }
            }

            onUpdated: canvas.requestPaint();
        }
    }
}