Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using PinchArea and MouseArea on the Canvas element
Forum Updated to NodeBB v4.3 + New Features

Using PinchArea and MouseArea on the Canvas element

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 137 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Synfony
    wrote on last edited by
    #1

    Hi,
    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);
                ctx.fill();
            }
            PinchArea{
                anchors.fill: parent
                pinch.target: myCanvas
                pinch.maximumScale: 10.0
                pinch.minimumScale: 0.1
                pinch.maximumRotation: 0 //360
                pinch.minimumRotation: 0 //-360
                pinch.dragAxis: Pinch.XAndYAxis
    
                onPinchStarted: {
                    if (pinch.active)
                        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:MouseArea
            }//end: PinchArea
        }//end:Canvas
    }
    

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

    Thank you.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved