Skip to content
  • 0 Votes
    2 Posts
    471 Views
    D

    I finally succeed to create this using 2 MultiPointTouchArea but I had to write drag function on touchUpdated event.

    Here is my code for one drag area:

    import QtQuick 2.0 Item{ id: joystick width: 100 height: 500 Rectangle{ id: joystickPad height: 50 width: 100 MultiPointTouchArea{ property var offset: null anchors.fill:parent minimumTouchPoints: 1 maximumTouchPoints: 1 function dragMove(point) { if (point) { var position = joystick.mapFromItem(joystickPad, point.x, point.y); /* Change y axis */ if((position.y - offset.y) < 0) { /* Do not go on top of drag area */ joystickPad.y = 0; } else { if((position.y - offset.y) > (joystick.height-joystickPad.height)) { /* Do not go below of drag area */ joystickPad.y = (joystick.height-joystickPad.height); } else { joystickPad.y = position.y - offset.y; } } } } onPressed: { var point = touchPoints[0]; offset = Qt.point(point.x, point.y); } onTouchUpdated: { var point = touchPoints[0]; dragMove(point); } onReleased: { //Reset position joystickPad.x = (joystick.width/2 - joystickPad.width/2) joystickPad.y = (joystick.height/2 - joystickPad.height/2) } } } }
  • 0 Votes
    2 Posts
    1k Views
    Z

    Ok i found the solution.

    I just set the parameter mouseEnabled:false of my MultiPointTouchArea.

    Qt doc =>
    "By default, the mouse will be handled the same way as a single touch point, and items under the touch area will not receive mouse events because the touch area is handling them. But if the mouseEnabled property is set to false, it becomes transparent to mouse events so that another mouse-sensitive Item (such as a MouseArea) can be used to handle mouse interaction separately."

    My bad, didnt read it correctly at first time :D

    And it's works with the maskedmousearea, nice !

    here is the sample :

    MultiPointTouchArea { anchors.fill: parent maximumTouchPoints:10; mouseEnabled:false /*here it is, epic ! */ Image{ width: 300; height: 300 id: myimage; source: "img/img.png" MaskedMouseArea { anchors.fill: parent alphaThreshold: 0.4 maskSource: myimage.source onPressed: { Console.log("win !") } } } }

    -i can know have toucharea with shape of images alpha channels => win
    -i can get rid of the childAt function => win
    -i can proceed to the next step of my work => win

  • 0 Votes
    1 Posts
    676 Views
    No one has replied
  • 1 Votes
    1 Posts
    627 Views
    No one has replied
  • 0 Votes
    7 Posts
    2k Views
    T

    @SGaist

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

  • 0 Votes
    1 Posts
    2k Views
    No one has replied