Select to view content in your preferred language

Why does MapGraphicsView not have a signal for mouse hover move?

1165
3
Jump to solution
04-19-2022 06:23 AM
TroyFoster
Frequent Contributor

From looking at the runtime Java's API their mouse moved signal is a hover move and mouse dragged is for when the user click and dragged the mouse on the map.  Why doesn't the runtime Qt have the same sort of setup for connecting to a signal for hover move events?

 

I currently have a workaround by creating a class inheriting QGraphicsItem and calling setAcceptHoverEvents on it.  However I have reports from our users that sometimes the QGraphicsItem class sometimes stops receiving any mouse events at all until the window is resized.

0 Kudos
1 Solution

Accepted Solutions
Tanner_Yould
Esri Contributor

Hi Troy, I hope I can help here. You can enable (or disable) mouse tracking on a `MapGraphicsView` when hovering with `setMouseTracking(bool enable) `, which it inherits from `QWidget`. To help test a solution, I added the following code block to our Display Map C++ Widget sample and the `mouseMoved` signal emits when I move my mouse around the map while hovering and prints the mouse's current xy position.

 

m_mapView->setMouseTracking(true);

connect(m_mapView, &MapGraphicsView::mouseMoved, this, [](QMouseEvent mouseEvent)
{
  qDebug() << mouseEvent.x() << mouseEvent.y();
});

 

I hope this helps and please let me know if there's anything else I can do.

Thank you!

Tanner Yould
Product Engineer
ArcGIS Maps SDK for Native Apps
Esri

View solution in original post

0 Kudos
3 Replies
Tanner_Yould
Esri Contributor

Hi Troy, I hope I can help here. You can enable (or disable) mouse tracking on a `MapGraphicsView` when hovering with `setMouseTracking(bool enable) `, which it inherits from `QWidget`. To help test a solution, I added the following code block to our Display Map C++ Widget sample and the `mouseMoved` signal emits when I move my mouse around the map while hovering and prints the mouse's current xy position.

 

m_mapView->setMouseTracking(true);

connect(m_mapView, &MapGraphicsView::mouseMoved, this, [](QMouseEvent mouseEvent)
{
  qDebug() << mouseEvent.x() << mouseEvent.y();
});

 

I hope this helps and please let me know if there's anything else I can do.

Thank you!

Tanner Yould
Product Engineer
ArcGIS Maps SDK for Native Apps
Esri
0 Kudos
TroyFoster
Frequent Contributor

That seems like it works but it breaks another workaround we have.  We used the QGraphicsItem's mouse moved signal and if it was a left click and drag would use that to query the items drawn on the map, and if it was a middle mouse click and drag we would take the event and change the button and pass that on to QGraphicsItem::mouseMoveEvent so the runtime Qt would see it as a drag operation and pan the map around.  Do you know of a way to re-map those buttons, either as a setting for just the esri software or to do it every time in the mouse moved signal?

0 Kudos
JamesBallard1
Esri Regular Contributor

Hi @TroyFoster. Let's try to get you a solution that doesn't involve remapping mouse buttons.

If I follow, what you're looking for is a way to differentiate between a "drag" (mouse is moving, while one or more buttons are pressed), and a "hover", meaning the mouse is moving over the map but not interacting (no buttons pressed).

You should be able to do this already with the mouseMoved event. You can check the QMouseEvent object and determine if any mouse buttons were pressed at the time of the move.

https://doc.qt.io/qt-5/qmouseevent.html#buttons

https://developers.arcgis.com/qt/cpp/api-reference/esri-arcgisruntime-mapgraphicsview.html#mouseMove...

Do you think that will work for your case?

0 Kudos