QML provides in its MouseArea component a PressAndHold signal, when a mouse area is pressed for a "long duration" http://doc.qt.io/qt-5/qml-qtquick-mousearea.html#pressAndHold-signal
this duration is set to 800ms, and I find nowhere a way to modify this duration. Can it be done and if so, how can I do that?
Thanks!
If you will see the MouseArea
source (Src/qtdeclarative/src/quick/items/qquickmousearea.cpp) you find this line:
d->pressAndHoldTimer.start(qApp->styleHints()->mousePressAndHoldInterval(), this);
The durations value came from QStyleHints
but it's read-only since the value is platform specified. So the answer to your question: "No", if you are not going to change the source.
But you still can emulate this events, for example:
MouseArea {
property int pressAndHoldDuration: 2000
signal myPressAndHold()
anchors.fill: parent
onPressed: {
pressAndHoldTimer.start();
}
onReleased: {
pressAndHoldTimer.stop();
}
onMyPressAndHold: {
console.log("It works!");
}
Timer {
id: pressAndHoldTimer
interval: parent.pressAndHoldDuration
running: false
repeat: false
onTriggered: {
parent.myPressAndHold();
}
}
}
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