Important: Please read the Qt Code of Conduct -

Propagate mouse event from Widget over QGraphicsView to QGraphicsView

  • I'm working on a project that has a QWidget (containing a stacked layout with widgets in each stacked Widget) over a QGraphicsView and want mouse events to pass to the QGraphicsView when the event is not over an interactive widget (combobox, button, etc.). For the overlying widgets, I reimplemented the mousePress/Move/Release events with just
    event->ignore()which I thought was supposed to pass the event to its parent. What seems to be happening (observed via GammaRay) is the event goes to the Stacked Widget then to the Widget containing the Stacked Layout (which is a child of the QGraphicsView) but stops there. How do I get it to continue to the QGraphicsView? Adding Qt::WA_TransparentForMouseEventsattribute to the overlying widget prevents any interaction with its child widgets, so that is not a solution for me.

  • Lifetime Qt Champion


    Is the widget part of the Graphics View ?

  • No, it is not. I think the thought was that since the widget was to remain fixed and not move when the view moved, that it should not be part of the scene. Its parent is the QGraphicsView, but it's not an item in the scene.

  • Probably not the cleanest solution, but a workaround would be to use an eventFilter. The QGraphicsView could call

    Then in the QGraphicsView, you override the method "eventFilter". That should receive the event originally destined to your widget. Be careful, handling event coordinates can be a bit messy.