Howto Drop into QGraphicsView/QGraphicsScene
I am quite new to Qt.
Basically I want to create a List holding Widgets derived from QGraphicsSVGItem.
Now I want to have a QGraphicsScene and a QGraphicsView displaying the scene.
It should be possible to drop my SvgItem into the GraphicsScene.
I have a hard time to understand what exactly I need to do.
I see, that I cannot acceptDrops directly inside the scene.
So could I create some kind of background item that resides also in the scene and will accept the drops?
Is this the right approach or can I somehow accept the incoming Items in the GraphicsView.
Set acceptDrops on the graphics view. Then reimplement QGraphicsScene's dragEnterEvent(), dragMoveEvent(), dragLeaveEvent() and dropEvent() according to your needs. You probably need to accept the drag action in dragEnterEvent() and dragMoveEvent(). This is done in the same way you would implement them on a widget. Then implement dropEvent() to handle the actual drop.
Funny, I just wrote code to do exactly this. I can add to Franzk's post, you need to accept the event in the enter and ove events if it's valid. Otherwise dropEvent won't be called when the user releases the mouse.
thanks a bunch. that did it. I found it confusing, that you accept the drops in the graphicsview and not in the scene.
It's not so confusing if you remember that the widget is the object that actually handles the events. In this case however, the events are relayed to the scene.