Eligijus Pupeikis
Eligijus Pupeikis

Reputation: 1125

Qml button press and hold does not trigger when moving mouse or finger

Pressing on Qml Button with mouse or finger(on touch enabled device) and moving too much will not emit pressAndHold() signal.

pressAndHold()

This signal is emitted when the button is interactively pressed and held down by the user via touch or mouse.

Moving very few pixels would emit pressAndHold() signal but it seems the threshold is very small and it is very apparent problem on touch enabled device where finger naturally moves a little when pressing on button. Therefore pressAndHold() signal would not be emitted reliably.

Upvotes: 0

Views: 1272

Answers (1)

Eligijus Pupeikis
Eligijus Pupeikis

Reputation: 1125

Solution:

Set startDragDistance property to higher than default value(10)

QGuiApplication::styleHints()->setStartDragDistance(100);

Explanation:

Looking at the QQuickAbstractButton source code one can find method:

void QQuickAbstractButtonPrivate::handleMove(const QPointF &point)

void QQuickAbstractButtonPrivate::handleMove(const QPointF &point)
{
    Q_Q(QQuickAbstractButton);
    QQuickControlPrivate::handleMove(point);
    setMovePoint(point);
    q->setPressed(keepPressed || q->contains(point));

    if (!pressed && autoRepeat)
        stopPressRepeat();
    else if (holdTimer > 0 && (!pressed || QLineF(pressPoint, point).length() > QGuiApplication::styleHints()->startDragDistance()))
        stopPressAndHold();
}

When distance from starting point to moved point is greater than QGuiApplication::styleHints()->startDragDistance() threshold stopPressAndHold() is called cancelling press and hold action.

Upvotes: 2

Related Questions