I’m trying to write a multi-touch desktop application. I have a QML based application and now I try to drag more than one QML element at the same time.
I tried to use MultiPointTouchArea
, but this doesen’t work. So I got 2 elements. For example 2 pictures, which should be draggable by two different persons at the same time.
If I define a rectangle containing the MultiPointTouchArea
and I link one touchPoint
with each picture, the first touch event moves the first picture and the second touch event moves the second picture.
Like in this example code:
Rectangle {
width: 400; height: 400
MultiPointTouchArea {
anchors.fill: parent
touchPoints: [
TouchPoint { id: point1 },
TouchPoint { id: point2 }
]
}
Rectangle {
width: 30; height: 30
color: "green"
x: point1.x
y: point1.y
}
Rectangle {
width: 30; height: 30
color: "yellow"
x: point2.x
y: point2.y
}
}
This is not what I’m looking for. I want them to move, if they are touched and dragged, both at the same time, without disturbing each other and without an order of touch events. Is this possible in qml? Or do I have to code a C++ function?
I hope you understand my problem.
I'm new to MultiPointTouchArea and doing some investigation, it appears that you have to dynamically allocate the point(i) to the first touched Rectangle(j).
In your example, you are doing a static allocation :
Rectangle(green) will follow point1 because you are doing so
x: point1.x
y: point1.y
Rectangle(yellow) will follow point2 because you are doing so
x: point2.x
y: point2.y
---> Green rectangle will never follow point 1 and the yellow one will never follow point 2.
MultiPointTouchArea has an array of touch points that you define, the first touch gesture that comes get served with first touch point and so on.
So you have to make a function or some hacking that checks the touch points state (pressed ...) ,rectangle state (add some boolean property ) and do the allocation.
Hope this will help,good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With