Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Prevent QGraphicsProxyWidget from sending (mouse) events to parent QGraphicsView
Qt 6.12 LTS is out! See what's new in the release blog

Prevent QGraphicsProxyWidget from sending (mouse) events to parent QGraphicsView

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 5.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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;
      }
      @

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt
                • Unsolved