【问题标题】:Qml button press and hold does not trigger when moving mouse or finger移动鼠标或手指时Qml按钮按住不触发
【发布时间】:2019-07-29 01:13:59
【问题描述】:

用鼠标或手指(在支持触摸的设备上)按下 Qml 按钮并移动太多不会发出pressAndHold() 信号。

pressAndHold()

当按钮被交互按下并且 用户通过触摸或鼠标按住。

移动很少的像素会发出 pressAndHold() 信号,但似乎阈值非常小,并且在启用触摸的设备上非常明显的问题,即在按下按钮时手指会自然移动一点。因此 pressAndHold() 信号不会被可靠地发出。

【问题讨论】:

    标签: qt button qml qtquick2


    【解决方案1】:

    解决方案:

    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()称为取消按住动作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多