Prevent QGraphicsProxyWidget from sending (mouse) events to parent QGraphicsView



  • I have added a QTextEdit as an item to a QGraphicsScene through a QGraphicsProxyWidget. But whenever I use the mouse (to for example select part of the text), those mouse events are also received in the QGraphicsView event handlers. How can I filter these events?



  • Hi crimson13,

    You can try reimplementing mouse events handlers of the QGraphicsProxyWidget class (mousePressEvent/mouseReleaseEvent/etc.) to return "true", which means "Don't propagate the event, it has be handled".

    @
    bool MyGraphicsProxyWidget::mousePressEvent ( QGraphicsSceneMouseEvent * event )
    {
    QGraphicsProxyWidget::mousePressEvent(event);
    return true;
    }
    @



  • Only 'bool event(QEvent * e)' returns a true to indicate the event was processed. The individual event handlers like mousePressEvent do not. Am I missing something? QEvent does have a setAccepted method, but I tried calling this and the results were the same.



  • The order is actually the other way around. First the event handler of the QGraphicsView is called and only then the handler of the QTextEdit. That makes more sense at least. It also solves my issue as I need to call event->accept() in the QTextEdit handler and then I can check isAccepted in the QGraphicsView derived class event handler (after calling the base handler) before doing anything with the event.



  • Yes, my bad. QEvent::setAccepted would be the way to do it. But after looking at the implementation of QGraphicsProxyWidget, it appears that those are already marked accepted anyway.

    Are they propagated beyond the QGraphicsView ? The view will anyway handle those events and translate them for your QGraphicsItems if I remember well. Then it doesn't mean they are propagated, just "processed" in the handler. You may check the "accepted" flag.

    Please let me know if you make any progress.

    Thanks



  • For the contextMenuEvent my plan (checking isAccepted in the QGraphicsView derived class) works fine. But mousePressEvent, etc always seem to return true for isAccepted even when not clicking on the QGraphicsProxyWidget. This doesn't sound strange as the QGraphicsView probably does something with the mouse events itself, but for my use case it's annoying.
    Basically I need to know WHO called 'accept' rather then just IF it was called, but that doesn't seem to be part of the framework.



  • Good, saw you post after writing mine.

    Finding which widget was hit is a bit harder yes. An easy/dirty way would be to set it in some shared space from your Widget, and read it back in your QGraphicsView class. As purely synchronous, this will work.

    Also the QGraphicsProxyWidget creates a local event specifically for the targeted widget, which is destroy at the end, and in a private implementation method. So no simple way to get the information back through the event.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.