【发布时间】:2019-07-29 01:13:59
【问题描述】:
用鼠标或手指(在支持触摸的设备上)按下 Qml 按钮并移动太多不会发出pressAndHold() 信号。
pressAndHold()
当按钮被交互按下并且 用户通过触摸或鼠标按住。
移动很少的像素会发出 pressAndHold() 信号,但似乎阈值非常小,并且在启用触摸的设备上非常明显的问题,即在按下按钮时手指会自然移动一点。因此 pressAndHold() 信号不会被可靠地发出。
【问题讨论】:
用鼠标或手指(在支持触摸的设备上)按下 Qml 按钮并移动太多不会发出pressAndHold() 信号。
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()称为取消按住动作。
【讨论】: