I am looking for a workaround to display coordinates in a label on my widget whenever mouse hovers on "mapGraphicsView" but it only works when i click and drag it besides it doesn't work, is there any way to do it by just hovering over the map and get coordinates as i am using geometry editor to draw a ployline and i need coordinates to always display when i draw a point on map.
m_mapView->setMouseTracking(true);
connect(m_mapView, &MapGraphicsView::mouseMoved, this, [](QMouseEvent &mouseEvent)
{
qDebug() << mouseEvent.pos().x() << mouseEvent.pos().y();
});
or any overriden event like this
void mouseMoveEvent(QMouseEvent *event);
Solved! Go to Solution.
Hi SWE, thanks for reaching out.
It looks like there may be a regression in the `MouseTracking` property of the QWidget class between Qt 5 and Qt 6 that we're going to look into.
In the meantime, as of ArcGIS Maps SDK for Qt version 200.2, we have a MapGraphicsView::hoverMoved method that should be what you're looking for.
connect(m_mapView, &MapGraphicsView::mouseMoved, this, [](QMouseEvent &mouseEvent)
{
qDebug() << "button pressed:" << mouseEvent.position().x() << mouseEvent.position().y();
});
// This is required for the hoverMoved signal to emit
m_mapView->setMouseTracking(true);
connect(m_mapView, &MapGraphicsView::hoverMoved, this, [this](QHoverEvent &hoverEvent)
{
qDebug() << "hovering:" << hoverEvent.position().x() << hoverEvent.position().y();
// convert screen location to map
const auto p = m_mapView->screenToLocation(hoverEvent.position().x(), hoverEvent.position().y());
qDebug() << "map coordinates:" << p.x() << p.y();
});
Let me know if this works, and thanks again for bringing this to our attention!
Hi SWE, thanks for reaching out.
It looks like there may be a regression in the `MouseTracking` property of the QWidget class between Qt 5 and Qt 6 that we're going to look into.
In the meantime, as of ArcGIS Maps SDK for Qt version 200.2, we have a MapGraphicsView::hoverMoved method that should be what you're looking for.
connect(m_mapView, &MapGraphicsView::mouseMoved, this, [](QMouseEvent &mouseEvent)
{
qDebug() << "button pressed:" << mouseEvent.position().x() << mouseEvent.position().y();
});
// This is required for the hoverMoved signal to emit
m_mapView->setMouseTracking(true);
connect(m_mapView, &MapGraphicsView::hoverMoved, this, [this](QHoverEvent &hoverEvent)
{
qDebug() << "hovering:" << hoverEvent.position().x() << hoverEvent.position().y();
// convert screen location to map
const auto p = m_mapView->screenToLocation(hoverEvent.position().x(), hoverEvent.position().y());
qDebug() << "map coordinates:" << p.x() << p.y();
});
Let me know if this works, and thanks again for bringing this to our attention!
Hey tanner,
That works and thanks for answering my query and i hope "mouseMove" function to be working on its intended purpose