I’m writing a program that uses the Qt Graphics View framework. I have subclassed QGraphicsItem to a class that includes other QGraphicsItem (or other subclasses of it). This class is the parent of the included QGraphicsItem; the idea is to work with composite objects.
From the docs it seems to be a conflict in what I try to achieve:
- Calling
ignore()inmousePressEventwill make my object unmovable. I want to move it. - Calling
accept()inmousePressEventwill prevent the event from being propagated to the child object. Some of the child objects should react to mouse events.
How can I make this work?
I think your interpretation of the documentation is incorrect.
I don’t believe that is true. To me it looks like calling
ignore()is like the object saying “I have assessed this event. I have taken all actions I want to in response to this event. I have also decided it was not intended for me, so I will now pass it on to the next object underneath me”. I can’t find anything which suggests the ignore event will unset theQGraphicsItem::ItemIsMovableflag (which is what decides if the QGraphicsItem is movable or not).I don’t see why you couldn’t make your object move and
ignore()the event, but I would advise that this is not a sensible approach (in most instances: obviously you may have cause for it).I believe this is true, but the parent can still modify its children. My understanding is calling
accept()is like the object saying “I have assessed this event. I have taken all actions I want to in response to this event (which may include modifying my children). I have also decided that the event was intended for me, so I will not be passing the event on”.