PDA

View Full Version : QGraphicsItem selectable and also draggable



corrado1972
30th November 2011, 07:56
I have a QGraphicsItem descendant that has flag ItemIsSelectable set.
Now I want to extend its behaviour allowing the user to drag and drop the item onto another item of the scene.
To do this, I studied the dragdroprobot demo and I overrided
mousePressEvent;
mouseMoveEvent;
mouseReleaseEvent;
like shown in the demo sources.

But, after this, the selection of the item is no more possible.

What should I do to fix this issue and get the item selectable and also droppable?
Is there any other demo or source that I could study?

meazza
30th November 2011, 14:35
Well once you override the functions mousePressEvent, mouseMoveEvent, mouseReleaseEvent the basic functionallity is disabled hence the problem of not beeing able to move it. So you also have to call the base implementation of these events.

And if you are looking for drag and drop functions take a look at dragEnterEvent, dragMoveEvent and dragDropEvent.

Just something to get you started.

corrado1972
30th November 2011, 16:39
It works!
Thanks for the suggestions too, I will follow them.