Reputation: 10273
In this example: http://www.java2s.com/Code/Cpp/Qt/InteractwithQGraphicsItem.htm
the itemChange() function is where all of the updating work takes place. However, this function doesn't seem to be called when I move the handles around. According to:
http://doc.qt.io/qt-4.8/qgraphicsitem.html#itemChange
it should be called whenever the state changes, which I would imagine would include the position. Can anyone explain how to make this function get called when the handles are moved?
Upvotes: 2
Views: 4250
Reputation: 12321
From the qt documentation check the QGraphicsItem::ItemPositionChange
:
The item's position changes. This notification is sent if the
ItemSendsGeometryChanges
flag is enabled, and when the item's local position changes, relative to its parent (i.e., as a result of callingsetPos()
ormoveBy()
). The value argument is the new position (i.e., aQPointF
). You can callpos()
to get the original position. Do not callsetPos()
ormoveBy()
initemChange()
as this notification is delivered; instead, you can return the new, adjusted position fromitemChange()
. After this notification,QGraphicsItem
immediately sends theItemPositionHasChanged
notification if the position changed.
So you should enable the flag QGraphicsItem::ItemSendsGeometryChanges
in order to have the itemChange
called when the position changes.
By default this is disabled for optimization:
For performance reasons, these notifications are disabled by default. You must enable this flag to receive notifications for position and transform changes. This flag was introduced in Qt 4.6.
In order to set a flag you should call the setFlag
function preferably in the constructor of your custom item.
item->setFlag(GraphicsItem::ItemSendsGeometryChanges);
Upvotes: 6