def itemChange(self, change, value): if change == QGraphicsItem.ItemSelectedHasChanged and self._resizable: if isinstance(value, int): self.enableHandle(value) else: self.enableHandle(value.toBool()) elif change == QGraphicsItem.ItemPositionChange: previousPos = self.pos() value = value if isinstance(value, QPointF) else value.toPointF() # check possible collision with parent and siblings if self.parentItem(): #leaf classes parentItem = self.parentItem() onSceneParentRect = parentItem.boundingRect() mappedParentRect = parentItem.mapRectToItem( parentItem, onSceneParentRect) x = value.x() if x < mappedParentRect.left( ) + NodeGraphicsItem.LEAFSIZE[0] / 2: x = mappedParentRect.left( ) + NodeGraphicsItem.LEAFSIZE[0] / 2 elif x > mappedParentRect.right( ) - NodeGraphicsItem.LEAFSIZE[0] / 2: x = mappedParentRect.right( ) - NodeGraphicsItem.LEAFSIZE[0] / 2 y = value.y() if y < mappedParentRect.top( ) + NodeGraphicsItem.LEAFSIZE[1] / 2: y = mappedParentRect.top( ) + NodeGraphicsItem.LEAFSIZE[1] / 2 elif y > mappedParentRect.bottom( ) - NodeGraphicsItem.LEAFSIZE[1] / 2: y = mappedParentRect.bottom( ) - NodeGraphicsItem.LEAFSIZE[1] / 2 value = QPointF(x, y) elif change == QGraphicsItem.ItemPositionHasChanged: self.model.pos = value if isinstance( value, QPointF) else value.toPointF() return super(NodeGraphicsItem, self).itemChange(change, value)