Hello,
I've had a similar problem and solved it by storing the mouse position in the onPressed event, but using it only when onPressAndHold and onReleased is called as in the following code example:
import QtQuick 2.11
Item {
id: root
Rectangle {
id: drawingArea
anchors.fill: parent
PinchArea {
id: pinchArea
anchors.fill: parent
property bool isDragging: false
pinch {
target: pattern
dragAxis: Pinch.XAndYAxis
}
onPinchStarted: pinchArea.isDragging = true
onPinchFinished: pinchArea.isDragging = false
} // end:PinchArea
Rectangle {
id: pattern
color: 'blue'
width: 20
height: 20
x: 10
y: 10
}
MouseArea {
id: mouseArea
property var _initialEvent: undefined
enabled: ! pinchArea.isDragging
anchors.fill: parent
onPressed: _initialEvent = Qt.point(mouse.x, mouse.y)
onPressAndHold: doStuff(Qt.point(mouse.x, mouse.y))
onPositionChanged: doStuff(Qt.point(mouse.x, mouse.y))
onReleased: doStuff(Qt.point(mouse.x, mouse.y))
// nothing to do, took over by pinchArea
onCanceled: _initialEvent = undefined
function doStuff(position) {
if (mouseArea._initialEvent !== undefined && mouseArea.enabled) {
console.log('Doing stuff with ', mouseArea._initialEvent.x, ':', mouseArea._initialEvent.y);
}
mouseArea._initialEvent = undefined;
console.log('Doing stuff with ', position.x, ':', position.y);
}
}// end: MouseArea
}
}
Simon