Important: Please read the Qt Code of Conduct -

Event handling with QGraphicsItems

  • Hey there! I am writing a QGraphicsItem implementation that draws and handles a resizable rectangle, and a QGraphicsScene with some code that handles screen area selection. Upon trying to resize the custom item the selection resizes as well. Since I am pretty bad at explaining I've attached a video demonstrating the problematic behaviour. What I would like to happen is that the one which started resizing first would be the only one resizing (that is, if I was to make a different selection the selection would resize and the custom rectangle would ignore it, and if I was to resize the rectangle the selection would stay unaltered). I am wondering is this possible?

    PS: As of right now I have the custom rectangle handling it's own resizing and the scene handling resizing the selection.

  • I've done some debugging and brainstoriming, and I found a way to prevent "corner catching", it's pretty simple, but I have problem where something along the event chain (calling QGraphicsScene::mouseMoveEvent(e)) something accepts the event. That only happens if I am moving my mouse inside the rectangle, outside it events are not accepted.

  • Solved it: by checking is the cursor in an "interactive" region of the graphics item in QGraphicsItem::mousePressEvent I can determine whether the item will become a mouse grabber (by either accepting or ignoring the event). When it comes to the graphics scene I simply prioritise the event propagation to the selection area resizing and I ignore accepted events.