QGraphicsItem's child item doesn't read the drag events
I've a QGraphicsItem, that has an other one parent to it.
Nothing fancy, none of the drag events on the child are detected, it moves the parent item instead.
Is there a way to say that this child item doesn't affect the parent ?
Thank you !
Items do not receive drag and drop events by default; to enable this feature, call setAcceptDrops(true).
This doesn't change anything,
still can't see my prints inside my drag methods. The parent is still moving.
I think the key is documentation statement:
"By accepting the event, (i.e., by calling QEvent::accept(),) the item will accept drop events, in addition to receiving drag move and drag leave. Otherwise the event will be ignored and propagate to the item beneath."
What I am sure about - I had implemented 2D "shape" editor myself and I had something you described and had no problem to separate child transformation from parent.
Without seen the code it is tough to provide more than general help..
class HandleItem(QtWidgets.QGraphicsItem): def __init__(self, parent): super(HandleItem, self).__init__(parent) self.setAcceptDrops(True) self.setAcceptHoverEvents(True) # + bounding rect() # + shape() # + paint() # + extra code def dragEnterEvent(self, event): event.accept() print 'resize start'
This item is simply parent under an other one
... handleInst = HandleItem(parent=self)
Is parent above child?
If not I am out of guesses. In C++ it used to work.
what do you mean by "Is parent above child?" ?
@Goffer I mean ZValue, but if I recall right this affect only siblings.
The only other guess I can make - problem might be related to wrong shape or bounding rectangle definition. Basically item is not found when clicked.
Well I think Z value is parent Z value + 1 when you parent unless you modify it (I didn't).
The shape is correct as my cursor changes when I hover it and my mousePressEvent is working perfectly.
This is very odd. Will keep investigasting
looking at some older codes, it seems that i already had the same problem and then used regular mousePress/Move/Release events with conditions.
might just do the same while looking for a better solution.