Using PinchArea and MouseArea on the Canvas element

  • Synfony about 4 hours ago

    I building a QtQuick app for the (Windows 10) Surface tablet.
    It's a sketching application where we are using mouse/Pen along with Touch gestures.
    So, I have placed the Canvas element with PinchArea and inside the PinchArea there is the MouseArea.
    Both Pinching and Mouse/Pen events are working except for the following glitch:
    I see that when I try to Pinch with fingers the first event that gets fired is the Mouse's onPressed event and then the pinch zoom happens.
    How do I stop the mouse onPressed getting fired in this case?
    I need to disable mouse event entirely when I am using my fingers to zoom.
    Here is the code snippet I am using:

    import QtQuick 2.12
    import QtQuick.Window 2.12
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        Canvas {
            id: myCanvas
            anchors.fill: parent
            property int pressedValue: 0
            property int pinchFlag: 0
            onPaint: {
                var ctx = getContext("2d");
                ctx.fillStyle = Qt.rgba(1, 0, 0, 1);
                ctx.moveTo(75, 50);
                ctx.lineTo(100, 75);
                ctx.lineTo(120, 50);
                ctx.lineTo(150, 50);
                ctx.lineTo(150, 25);
                ctx.lineTo(5, 15);
                anchors.fill: parent
                pinch.maximumScale: 10.0
                pinch.minimumScale: 0.1
                pinch.maximumRotation: 0 //360
                pinch.minimumRotation: 0 //-360
                pinch.dragAxis: Pinch.XAndYAxis
                onPinchStarted: {
                    if (
                        myCanvas.pinchFlag = 1
                onPinchFinished: {
                    myCanvas.pinchFlag = 0
                MouseArea {
                    anchors.fill: parent
                    acceptedButtons: Qt.AllButtons
                    onPressed: {
                        if(myCanvas.pinchFlag ===0){
                            myCanvas.pressedValue = myCanvas.pressedValue +1
                            console.log("Pressed: " + myCanvas.pressedValue)
            }//end: PinchArea

    I am really struggling with this. Please provide your help.
    Thank you.

  • Hi,
    I asked the same thing a month ago:
    No answer yet...

Log in to reply