Howto Drop into QGraphicsView/QGraphicsScene
-
Hello,
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.
Thanks.
-
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.
-
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.
@Franzk said in Howto Drop into QGraphicsView/QGraphicsScene:
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.
thanks a lot for your answer! confusing me long long time why dropEvent in QGraphicsView alway not active and now i finally know i missing two event->accept() in that two function
-
Hello,
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.
Thanks.
This post is deleted!