MultiPointTouchArea: onRelease called twice?



  • I am playing with MultiPointTouchArea in a Canvas component to make a little drawing exercise. The code below works but the onReleased event is getting called twice and I don't understand why.

    From the log statements below, I see it gets called first with one TouchPoint, then again with two TouchPoints – the x and y positions are the same for all. Also the id of these touchPoints are undefined.

    I don't get it. Since I define a maximumTouchPoints and am testing with just one touch (I am testing this on my laptop using a trackpad, with just one "finger".) :

    • why am I getting multiple touchpoints
    • why is onReleased getting called twice?
    • why are the touchPoints id undefined, since I have defined my touchPoints?

    Log statements:

    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();
                }
            }
        }
    
    

  • Lifetime Qt Champion

    Hi and welcome again to devnet :)

    Looks strange indeed. What version of Qt and OS are you using ?



  • @SGaist

    Hi – using Qt 5.5.1 on OSX 10.11.12

    It doesn't seem like it should be doing this – but I am testing on the desktop, if that matters (why would it?).

    I noticed another anomaly:

    TouchPoint.previousX and TouchPoint.previousY are always 0 when running on the desktop but in the iOS simulator, they reprt accurate values. This seems like a bug – unless there is something really basic which I am missing.


  • Lifetime Qt Champion

    Something to investigate, did you already check the bug report system ?



  • @SGaist

    The "two release events" issue has been reported and is open: https://bugreports.qt.io/browse/QTBUG-44781

    The "no "previousX, previousY" issue is there too: https://bugreports.qt.io/browse/QTBUG-41692


  • Lifetime Qt Champion

    You should vote for the bugs and add additional information if you can.



  • @SGaist

    Yeah, I did. They have been open for a while now.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.