用鼠标或手指按下Qml按钮(在启用触摸的设备上)并且移动太多不会发出pressAndHold()信号。
压制控股()
当用户通过触摸或鼠标交互地按下按钮时发出该信号。
移动非常少的像素会发出pressAndHold()信号,但似乎阈值非常小,并且在按下按钮时手指自然移动一点的触摸启用设备上是非常明显的问题。因此,pressAndHold()信号不会可靠地发出。
将startDragDistance属性设置为高于默认值(10)
QGuiApplication::styleHints()->setStartDragDistance(100);
查看QQuickAbstractButton源代码,可以找到方法:
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();
}
当从起点到移动点的距离大于QGuiApplication::styleHints()->startDragDistance()
阈值时,stopPressAndHold()
称为取消按住动作。