Drag&Drop QPushButton between QFrame and QGraphicsView
-
Hi community !
I am playing with drag&drop in order to make a fancy project in the upcoming weeks
for now I can drag&drop a QPushButton (and any other widget I presume...) from a QFrame to an other, inserting it in a layout inbetween widgets at the right position.Then I wanted to try to drag&drop from a QFrame to a QGraphicsView, I can drag&drop from the QGraphicsView to the QFrame but I can't parent it back to my QGraphicsView.
I've sub classed QGraphicsView and QGraphicsScene (QFrame and my QPushButton obviously)
When I initialize my test I start with my QPushButton inside my QGraphicsViewdef __init__(self, parent): """Initialize ClassName.""" super(DDbase_graphicsView, self).__init__(parent) self.setAcceptDrops(True) self.scn = DDbase_graphicsScene(self) btn = DD_button(self) btn.setText('Drag me') self.setScene(self.scn)
So I have my button and I can drag&drop it inside my QGraphicsView (scene)
if I check the parent of this QPushButton, it returns the subclassed QGraphicsView.
Then I drag&drop to the QFrame, the parent of the QPushButton is now the sub classed QFrame.
And when I try to drag&drop back to the QGraphicsView it does nothing, even though it prints everything inside the dropEvent and other events in my QGraphicsScene sub class, the parent of the QPushButton is still the sub classed QFrame...if in the first line of my dropEvent is set
event.source().setParent(self.parent()) # the QGraphicsView
then the QPushButton disappears .... If I set the parent to None, the QPushButton goes back to the QGraphicsView but drag&drop to the QFrame becomes impossible ... and drag&drop inside the QGraphicsView seems to be screwed up (but in this specific case, it's maybe a loop missing.)
Do you guys have any idea ? I think it has to do with the parenting ... but i m not 100% sure and I can't find any solution.
Thanks !