I'm working on a Qt application and I have a problem with getting mouse events where I want them.
Here's a high-level view of what I have (there are other things going on at each level that dictate the need for the views and scenes):
+----------------
| App Window -- QMainWindow
| +--------------
| | View -- QGraphicsView --- Grabbing mouse events here for Mode 1
| | +------------
| | | Scene -- QGraphicsScene
| | | +----------
| | | | Image -- QGraphicsPixmap --- Want to grab mouse events here for Mode 2
| | | |
In Mode 1, I'm grabbing the event mousePressEvent at the View level. In Mode 2, I'd like to grab the mouse events at the Image level. Before I overloaded mousePressEvent in the View class I was able to get all events in Image. Now that I'm capturing at View I can't get mouse events in Image. Image is private within Scene and I don't want to expose it.
There is no inheritance here; each item is an object created by the object above it.
Reading through this question Qt -- pass events to multiple objects? makes it seem like I want to capture mouse events at the Image level and let them go back up; however, I would still need to create mousePressEvent in View and I'd be right back where I am.
Is there a way to turn on/off event handling during run-time and make sure they get to the lower levels? Or is there a way to forward events to a sub-object?
Is there a way to turn on/off event handling during run-time and make sure they get to the lower levels? Or is there a way to forward events to a sub-object?
There are some possibilities :
At runtime, it's possible to turn off/on mouse event with the method QGraphicsItem::setAcceptedMouseButtons(...).
There are many other possibilities...
Hope it helps !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With