用鼠标或手指(在启用触摸功能的设备上)按下Qml按钮并移动太多不会发出pressAndHold()信号。
pressAndHold()
当交互式按下按钮并 由用户通过触摸或鼠标按住。
移动很少的像素会发出pressAndHold()信号,但是阈值似乎很小,这在支持触摸的设备上非常明显,因为在按下按钮时手指自然会稍微移动一点。因此pressAndHold()信号将无法可靠地发出。
答案 0 :(得分:2)
将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()
时,称为取消按住动作。