Shuji
Shuji

Reputation: 666

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

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?

Upvotes: 0

Views: 348

Answers (1)

eyllanesc
eyllanesc

Reputation: 244212

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);
# ...

Upvotes: 1

Related Questions