PDA

View Full Version : best way to detect when user stops moving a QGgraphicsItem



amleto
15th June 2013, 15:22
I'm messing around with simple selectable + movable tiles in a graphics view/scene. When the user releases the LMB after dragging a Qgraphicsitem I want to invoke some actions.

Do I have to sub-class the scene/item and watch mouse events to identify this?

d_stranz
16th June 2013, 04:06
I am hard pressed to figure out how to retrieve the identity of a QGraphicsItem from a QGraphicsScene::dropEvent() if you install an event filter on the scene (or view). It looks like the best you can do is retrieve the coordinates from the event, then query the scene for the item at that location. It seems stupid if Qt makes you subclass all QGraphicsItem types just to handle drag / drop.

Have you looked at the code for the elasticnodes example? Does that use drag / drop to move the nodes?

amleto
16th June 2013, 18:09
I looked at that example - the moving of the nodes is just done with 'normal' graphics view implementation and there is no 'drop' notification anywhere.

the example uses a Scene method ( QGraphicsItem *mouseGrabberItem() const; ) to identify when a node is being held by a user.