PDA

View Full Version : Qgraphicsitem grabbed with mouse.



repka3
31st August 2009, 15:34
Hi all,
I need to know in mouseMoveEvent of the scene class (derived from QGraphicsScene) if i'm currently moving an item in the scene.

Items have flag ItemIsMovable but this flag is not always enabled because if the user click and drag in a particular spot of items i need to do something else and not moving the item.

The only way i can accomplish this work is:

-in mousePressEvent of item set a flag
item_grabbed_for_moving=true if the user click everywhere in items
item_grabbed_for_moving=false if the user click in that particular spot in the items

-in mouseReleaseEvent of items
item_grabbed_for_moving=false;

-in mouseMoveEvent of Scene check if:
mouseGrabberItem() has item_grabbed_for_moving==true.


QGraphicsItem* t=mouseGrabberItem();
if(t && t->type()==soa_item::Type && ((soa_item*)t)->IsItemMoving()){
qDebug("You are currently moving a soa_item.");
}


I think this is a bad way and i want to ask you if there is another,more clean, way to do this.

Thx for answer.
bye