PDA

View Full Version : posChanged() for QGraphicsItem?



blooglet
17th February 2011, 13:35
Is it possible to detect changes in the position of a QGraphicsItem? I need to update other data when the position changes. I tried reimplementing all setPos functions, but when I drag an item across my graphics scene these functions are not called so the other data isn't updated.

MarekR22
17th February 2011, 14:05
see QGraphicsItem::itemChange and enum QGraphicsItem::GraphicsItemChange value QGraphicsItem::ItemPositionHasChanged or QGraphicsItem::ItemScenePositionHasChanged (depending what you want). Note that you have to set a flag QGraphicsItem::ItemSendsGeometryChanges for the item (QGraphicsItem::setFlag).

another thing there is a Qt bug for QGraphicsItem::ItemScenePositionHasChanged. You have to set flag ItemSendsGeometryChanges for all parents (to the root parent) to get proper notifications about scene position change.