QGraphicsItem ItemIsMoveable | restrict movement of Item
-
Hello guys,
i do have a custom QGraphicsItem that is a child of another QGraphicsItem.
The child Item has the ItemIsMoveable Flag set.I would like to restrict the areas the child Item can be moved to, but i don't know which function i have to reimplement.
I tried to implement these two:
dragMoveEvent(QGraphicsSceneDragDropEvent *)
dropEvent(QGraphicsSceneDragDropEvent *)But they did not get called.
Can anyone tell me what i can do to restrict the areas the child item can be moved to?
Thanks
Michael -
You can reimplement the itemChange() method to achieve what you want. Note, you have to ensure the
QGraphicsItem::ItemSendsGeometryChanges
flag is set for your QGraphicsItem for itemChange() to be called. -
Hi,
In which area should the restriction happen ?
-
You can reimplement the itemChange() method to achieve what you want. Note, you have to ensure the
QGraphicsItem::ItemSendsGeometryChanges
flag is set for your QGraphicsItem for itemChange() to be called. -
@MichaelH said in QGraphicsItem ItemIsMoveable | restrict movement of Item:
dragMoveEvent(QGraphicsSceneDragDropEvent *)
dropEvent(QGraphicsSceneDragDropEvent *)Btw these two are Drag'n'Drop Events. They have nothing to do with the basic movement of
QGraphicsItems
(i.e. simple changes of position) -
Thanks for all the answers!
@SGaist i want the child item to be only moveable within the parent area.
@mchinand, @Asperamanca
i will try the itemChange() method and see if it works.@Pl45m4 thats also what i thought but i did not find a more similar function than these two
Edit:
The itemChange Method works just fine!