How to pan QML Map as soon as one press and start dragging mouse pointer on it?

徘徊边缘 提交于 2020-02-25 07:06:07

问题


I have enabled gestures like this:

gesture.enabled: true

but the map doesn't start panning as soon as I press and start moving the mouse pointer instead the map start panning when I have already dragged the mouse pointer over 10 pixels or so!

Can somebody please help me to let me start panning the map as soon as the mouse pointer start dragging instead waiting for the 10 or so pixels drag wait?


回答1:


If the MapGestureArea source code is analyzed then it is observed that the threshold used depends on QStyleHints::startDragDistance:

bool QQuickGeoMapGestureArea::canStartPan()
{
    if (m_allPoints.count() == 0 || (m_acceptedGestures & PanGesture) == 0
            || (m_mousePoint && m_mousePoint->state() == Qt::TouchPointReleased)) // mouseReleaseEvent handling does not clear m_mousePoint, only ungrabMouse does -- QTBUG-66534
        return false;

    // Check if thresholds for normal panning are met.
    // (normal panning vs flicking: flicking will start from mouse release event).
    const int startDragDistance = qApp->styleHints()->startDragDistance() * 2;
    QPointF p1 = mapFromScene(m_allPoints.at(0).scenePos());
    int dyFromPress = int(p1.y() - m_sceneStartPoint1.y());
    int dxFromPress = int(p1.x() - m_sceneStartPoint1.x());
    if ((qAbs(dyFromPress) >= startDragDistance || qAbs(dxFromPress) >= startDragDistance))
        return true;
    return false;
}

So the solution is to modify that property (the setter method of startDragDistance is not documented for what is probably a bug):

# ...
QGuiApplication app(argc, argv);
app.styleHints()->setStartDragDistance(0);
# ...


来源:https://stackoverflow.com/questions/60136395/how-to-pan-qml-map-as-soon-as-one-press-and-start-dragging-mouse-pointer-on-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!