MultiPointTouchArea和Canvas

时间:2016-01-08 13:33:22

标签: qt qml qt-quick

我在MultiPointTouchArea组件中使用Canvas进行一些绘画练习。下面的代码有效,但onReleased事件被调用两次,我不明白为什么。

从下面的日志语句中,我看到首先使用一个TouchPoint调用它,然后再调用两个TouchPoints - x和y位置对所有人都相同。此外,这些touchPoints的id未定义。

我不明白。由于我定义了一个maximumTouchPoints并且只用一次触摸进行测试(我正在使用触控板在我的笔记本电脑上进行测试,只有一个“手指”。):

  • 为什么我会得到多个接触点
  • 为什么onReleased被调用两次?
  • 为什么touchPoints id未定义,因为我已经定义了touchPoints?
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();
        }
    }
}

1 个答案:

答案 0 :(得分:1)

所以似乎这些问题存在漏洞

已报告“两个发布事件”问题并且已打开:https://bugreports.qt.io/browse/QTBUG-44781

还有“no previousX,previousY”TouchPoint问题:https://bugreports.qt.io/browse/QTBUG-41692