Qt鼠标移动事件未被事件过滤器捕获 [英] Qt mouse move events not caught by an event filter

查看:892
本文介绍了Qt鼠标移动事件未被事件过滤器捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的事件过滤器:

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

返回true;
}
else
{
return false;
}
}
else
{
//将事件传递给父类
返回QWidget :: eventFilter(obj,ev);
}
}

我安装了这样的过滤器:

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

事件过滤器似乎捕获mousePress和mouseRelease事件,但不是mouseMove。 / p>

可能是什么问题?

解决方案

事实证明,正在寻找错误的mouseMove事件。



我应该捕捉到 QEvent :: GraphicsSceneMouseMove 事件而不是 QEvent :: MouseMove 事件。


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

Here's 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 install the filters like this:

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

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

What could be the problem?

解决方案

It turns out that I was looking for wrong kind of mouseMove events.

I should've been catching QEvent::GraphicsSceneMouseMove events instead of QEvent::MouseMove events.

这篇关于Qt鼠标移动事件未被事件过滤器捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆