PDA

View Full Version : Overload QGraphicsItem Move in Scene



D Cell
1st March 2010, 03:59
Hi. I have a class that inherits QGraphicsItem. I have set the QGraphicsItem::ItemIsMoveable flag in the class constructor so that I can move the item around the scene by grabbing and dragging. I want to overload the QGraphicsItem function responsible for this move functionality so that I can save the new position to a database whenever the item is moved in the scene. I have tried overloading the QGraphicsItem::setPos(), QGraphicsItem::moveBy(), and QGraphicsItem::setTransform() functions, but these do not seem to be used by the scene for moving. Can somebody please tell me what function is called by the scene during this type of move so that I know what function to overload? Thanks.

prof.ebral
1st March 2010, 05:58
http://doc.trolltech.com/4.6/qgraphicsitem.html#GraphicsItemChange-enum

D Cell
16th March 2010, 05:14
Thanks for the link. Once I finally got back to this issue, it sent me in the right direction. What I ended up doing was:

in the class constructor:


setFlag(QGraphicsItem::itemSendsScenePositionChang es);
setFlag(QGrpahicsItem::itemSendsGeometryChanges);

in the overlaoded itemChange(GraphicsItemChange change, const QVariant &value) function:


if ((change == QGraphicsItem::ItemScenePositionHasChanged || change == QGraphicsItem::ItemTransformHasChanged || change == QGraphicsItem::ItemPositionHasChanged) && scene())
{
//update position in database
}