Solved MultiPointTouchArea - Drag and Drop
-
I am writing a multi-touch application and I want to be able to drag multiple targets simultaneously, so I cannot use the standard MouseArea. So far, this approach works for me:
import QtQuick 2.5 import QtQuick.Window 2.1 Window { id: window visible: true width: 1280; height: 960 Item { id: root anchors.fill: parent Repeater { model: 4 Repeater { property var j: modelData model: 4 Rectangle { property var i: modelData x: parent.width*i/4; y: parent.height*j/4 width: 64; height: 64 color: Qt.rgba(i/4, j/4, 0, 1) MultiPointTouchArea { property var drag: parent property var offset: null anchors.fill: parent enabled: true minimumTouchPoints: 1 maximumTouchPoints: 1 function dragMove(holder, point) { if (point && drag) { var position = holder.mapFromItem(drag, point.x, point.y); drag.x = position.x - offset.x; drag.y = position.y - offset.y; } } onPressed: { var point = touchPoints[0]; offset = Qt.point(point.x, point.y); dragMove(root, point); } onTouchUpdated: { var point = touchPoints[0]; dragMove(root, point); } onReleased: { var point = touchPoints[0]; dragMove(root, point); } } } } } } }
However, this works well for moving things around, but I am stuck making it work with the Qt's Drag and Drop mechanism. Is there any way to make this work with DropArea (i.e. make it emit the entered/exited/dropped events)?
-
Actually, calling Drag.start, Drag.drop, and Drag.cancel appears to make it work. I was scratching my head over this but it turns out I had an event filter interfering...