[PyQt] Handling QGraphicsItem snapping outside of itemChange
Devan Richmond
devan.richmond at gmail.com
Wed Feb 25 09:45:24 GMT 2015
Hi,
I've been trying to create a snap to grid type system for QGraphicsScene and
it seems that most solutions rely on altering the item itself in it's itemChange
method. The problem I have with that solution is that it will also affect
what happens when you use QGraphicsItem::setPos
My ideal solution would decouple the items from any notion of grid snapping such
that the QGraphicsScene deals exclusively with the snapping.
# QGraphicsScene::mouseMoveEvent
def mouseMoveEvent(self, event):
# snapping logic
event.setScenePos(QtCore.QPointF(x, y))
super().mouseMoveEvent(event)
I know that QGraphicsSceneMouseEvent::setScenePos is internal and not public but
it demonstrates what type of functionality I'm aiming for. Similarly, the
constructor is also internal so I can't subclass or create a new instance to
inject my own event.
A kick in the right direction about how to implement something like this without
using undocumented functions would be much appreciated.
Thanks
More information about the PyQt
mailing list