Qt mouse move events do not fall into event filter

I can't seem to catch QEvent :: MouseMove in event events in my eventFilter.

Here is my event filter:

bool MapWidget_c::eventFilter( QObject *obj, QEvent *ev ) { if( obj == graphicsGeoMap_mp || obj == graphicsScene_mp || obj == graphicsView_mp ) { if( ev->type() == QEvent::MouseMove ) { QMouseEvent *mouseEvent = static_cast< QMouseEvent* >( ev ); mouseMoveEvent( mouseEvent ); return true; } else { return false; } } else { // pass the event on to the parent class return QWidget::eventFilter( obj, ev ); } } 

I set the filters as follows:

 graphicsGeoMap_mp->installEventFilter( this ); //QGraphicsGeoMap graphicsScene_mp->installEventFilter( this ); //QGraphicsScene graphicsView_mp->installEventFilter( this ); //QGraphicsScene 

The event filter seems to capture mousePress and mouseRelease events are just fine, but not mouseMove.

What could be the problem?

+4
source share
2 answers

Turns out I was looking for the wrong mouseMove events.

I should catch QEvent::GraphicsSceneMouseMove events instead of QEvent::MouseMove events.

+5
source

Mouse movement events are usually not included. You need to enable mouse tracking (via setMouseTracking ) on your wigdet (s) to get them.

From QMouseEvent :

Mouse movement events will only occur when the mouse button is clicked, if mouse tracking was not enabled using QWidget :: setMouseTracking ().

+3
source

All Articles