Select to view content in your preferred language

mapGraphicsView mouseMove event only works on click and drag instead of just hover??

207
2
Jump to solution
a month ago
Labels (3)
SWE
by
New Contributor II

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

0 Kudos
1 Solution

Accepted Solutions
Tanner_Yould
Esri Contributor

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!

Tanner Yould
Product Engineer
ArcGIS Maps SDK for Native Apps
Esri

View solution in original post

2 Replies
Tanner_Yould
Esri Contributor

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!

Tanner Yould
Product Engineer
ArcGIS Maps SDK for Native Apps
Esri
SWE
by
New Contributor II

Hey tanner,
That works and thanks for answering my query and i hope "mouseMove" function to be working on its intended purpose

0 Kudos