Reputation: 1636
I have a mouse area that has something like this
onPressed: {
cursorShape = Qt.ClosedHandCursor
console.log("closed")
}
onReleased: {
cursorShape = Qt.OpenHandCursor
console.log("open")
}
cursorShape: Qt.OpenHandCursor
If I click and release without any mouse movement, the cursor icon changes as expected. If I move the mouse while clicked though, the cursor icon remain a closed hand.
Why is that?
Upvotes: 3
Views: 1442
Reputation: 7170
I've just checked the behaviour is right with the following code in QML .
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
ApplicationWindow {
id: mainwindow
width: 640
height: 480
visible: true
Flickable {
width: 200; height: 200
contentWidth: image.width
contentHeight: image.height
clip: true
Image {
id: image;
source: "images/icon.png"
MouseArea {
anchors.fill: parent
preventStealing: true
onPressed: {
cursorShape = Qt.ClosedHandCursor
console.log("closed")
}
onReleased: {
cursorShape = Qt.OpenHandCursor
console.log("open")
}
cursorShape: Qt.OpenHandCursor
}
}
}
}
Setting preventStealing as true
gets the MouseArea
working fine and the cursorShape
changes ok. But the drawback (a BIG drawback) is the flick gesture is stolen by the MouseArea
so the flick movement is not generated.
So, I recommend handling onMovementEnded
to set the cursorShape = Qt.OpenHandCursor
when the user interaction ends.
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
ApplicationWindow {
id: mainwindow
width: 640
height: 480
visible: true
Flickable {
width: 200; height: 200
contentWidth: image.width
contentHeight: image.height
clip: true
onMovementEnded: {
mousearea.cursorShape = Qt.OpenHandCursor
console.log("onMovementEnded")
}
Image {
id: image;
source: "images/icon.png"
MouseArea {
id: mousearea
anchors.fill: parent
onPressed: {
cursorShape = Qt.ClosedHandCursor
console.log("closed")
}
onReleased: {
cursorShape = Qt.OpenHandCursor
console.log("open")
}
cursorShape: Qt.OpenHandCursor
}
}
}
}
Upvotes: 2