Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML: is it possible to change the long duration of a mouse Area

Tags:

qt

qml

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!

like image 635
Zed Avatar asked Dec 02 '22 17:12

Zed


1 Answers

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();
        }
    }
}
like image 52
folibis Avatar answered Dec 23 '22 08:12

folibis