@nedo99: A big thanks for the tip! That in fact solved my problem, but maybe not in the way you might have thought! I finally got it to work this way:
MouseArea {
id: myMouseArea
property point cursorPos
property bool cursorPosActive : false
// new code to handle flicking
property point startFlickContentRef: Qt.point(0, 0)
property point startFlickMousePos: Qt.point(mouseX, mouseY)
property bool flicking: false
function setStartFlickMousePos(x,y) {
// "prepare" for flicking whenever we have a legitimate mouse pos...
if (!flicking) // ...but are not actually flicking!
startFlickMousePos = Qt.point(x,y)
}
function startFlick(refPt) {
// Note: startFlick() might be called multiple times before endFlick() is called...
if (!flicking) { // ...so this is an important check!
startFlickContentRef = refPt
flicking = true
}
}
function endFlick(refPt) {
if (flicking) {
var diffX = refPt.x - startFlickContentRef.x
var diffY = refPt.y - startFlickContentRef.y
statBar.cursorPos =
Qt.point(startFlickMousePos.x + diffX,
startFlickMousePos.y + diffY)
flicking = false
}
}
anchors.fill: parent
hoverEnabled: true
onClicked: { // MouseEvent OK
cursorPos = Qt.point(mouse.x, mouse.y)
setStartFlickMousePos(mouse.x, mouse.y)
}
onEntered: { // here: mouseX/Y OK?
cursorPos = Qt.point(mouseX, mouseY)
setStartFlickMousePos(mouseX, mouseY)
cursorPosActive = true
}
onExited: { cursorPosActive = false }
onPositionChanged: { // MouseEvent OK
cursorPos = Qt.point(mouse.x, mouse.y)
setStartFlickMousePos(mouse.x, mouse.y)
}
onWheel: { // WheelEvent OK
cursorPos = Qt.point(wheel.x, wheel.y)
setStartFlickMousePos(wheel.x, wheel.y)
wheel.accepted = false; // pass to Flickable
}
}
Then I added the following code to my Flickable:
onFlickStarted: {
myMouseArea.startFlick(Qt.point(contentX, contentY))
}
onFlickEnded: {
myMouseArea.endFlick(Qt.point(contentX, contentY))
}
Note that it turned out to be important to use onFlickStarted/Ended instead of onMovementStarted/Ended. Also it's important to update the startFlickMousePos at every opportunity, because at the point where I normally would want to set it (in startFlick()), I might not have a valid mouseX and mouseY (that was the reason for this post in the first place!).
Again thanks! Together we are strong!