我似乎无法在eventFilter中捕获QEvent :: MouseMove类型的事件. 这是我的事件过滤器: boolMapWidget_c::eventFilter( QObject *obj, QEvent *ev ){ if( obj == graphicsGeoMap_mp || obj == graphicsScene_mp || obj == graphicsVie
这是我的事件过滤器:
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 ); } }
我像这样安装过滤器:
graphicsGeoMap_mp->installEventFilter( this ); //QGraphicsGeoMap graphicsScene_mp->installEventFilter( this ); //QGraphicsScene graphicsView_mp->installEventFilter( this ); //QGraphicsScene
事件过滤器似乎捕获mousePress和mouseRelease事件就好了,但不是mouseMove.
可能是什么问题呢?
事实证明,我正在寻找错误的mouseMove事件.我应该一直在捕捉QEvent :: GraphicsSceneMouseMove事件而不是QEvent :: MouseMove事件.