本文介绍了一按就如何平移QML Map并开始在其上拖动鼠标指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我启用了以下手势:

gesture.enabled: true

但是当我按下鼠标并开始移动鼠标指针时,地图并不会立即开始平移,而是当我已经将鼠标指针拖动到10像素左右时,地图才开始平移!

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!

一旦鼠标指针开始拖动,而不是等待10个像素左右的拖动等待,有人可以帮我让我开始平移地图吗?

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?

推荐答案

如果分析了MapGestureArea源代码,然后观察到所使用的阈值取决于 QStyleHints::startDragDistance :

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;
}

因此解决方案是修改该属性(没有记录startDragDistance 可能是一个错误):

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

这篇关于一按就如何平移QML Map并开始在其上拖动鼠标指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 06:42