Question

I have a class "SceneWindow" which inherits QGraphicsScene. I have a mouse move event which emits the current x and y position of the mouse on the scene.

In my main window class I have four graphicsview which I use to display different images. I have created four objects of the same graphicsscene class to set on the view. I want to detect on which of the graphics view my mouse currently is. How do I do it? I tried using event filter in main class to detect the view but it is not helping. I tried it in the following way:

bool MainWindow::eventFilter(QObject *f_object, QEvent *f_event)
{
  if(f_object == graphicsView && f_event->type() == QEvent::MouseMove)
  {
     qDebug() << "I am in Scene 1";
  }

Can someone please give a solution to this?

Thank You.

Was it helpful?

Solution

*Making the answer from comment...

The problem is that you install the event filter on the QGraphicsView, however mouse events are handled by rather viewport than the view itself. Therefore, to make your event filter "catch" the mouse events you need to install it on the viewport:

graphicsView->viewport()->installEventFilter(filter);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top