How to trap qgraphicsitem inside another qgraphicsitem?
-
Hi, I'm trying to create a movable QGraphicsItem, but I want it to be movable only inside the boundings of another QGraphicsRectItem, I want it so that it stops at the edge when I try to move my item outside of the RectItem, similar to how mouse cursor stops at the end of the screen. I'm guessing I can do this using collision detection but have no idea where to go.
Thanks for help,
Mat -
Hi, I'm trying to create a movable QGraphicsItem, but I want it to be movable only inside the boundings of another QGraphicsRectItem, I want it so that it stops at the edge when I try to move my item outside of the RectItem, similar to how mouse cursor stops at the end of the screen. I'm guessing I can do this using collision detection but have no idea where to go.
Thanks for help,
Mat@MatheusIH
overrride QGraphicsItem::itemChange() method.
The example in the docs already almost does what you need. Adapt it to bound the coordinates to the parent item instead.