featuring QGraphicsItem::itemChange() . If you have an item that you want to limit to a specific area, override itemChange() for that item and monitor the QGraphicsItem::ItemPositionHasChanged changes to see if you want items to be placed outside your area of ββinterest and prevent this by returning a position from within that area . eg:
QVariant QGraphicsItem::itemChange(GraphicsItemChange change, const QVariant &value) { switch (change) { case ItemPositionHasChanged: if(x() < -200 || y() < -200 || x() > 200 || y() > 200) setPos(0, 0); graph->itemMoved(); break; default: break; }; return QGraphicsItem::itemChange(change, value); }
source share