问题
I inherited from the QGraphicsObject
and created a new class that has a pixmap and sets its transform origin point to:
setTransformOriginPoint(boundingRect().center());
But when I call setRotation()
on the my class (which is added to a QGraphicsView
using the scene), the rotation doesn't use the center as the rotation anchor. How can I set the center to be the anchor of the rotation ? Thanks !
More information: calling setRotation() outside of a sceneEvent function it works, but inside a sceneEvent, upon a pinch gesture, the origin point doesn't work.
回答1:
Draw pixmap at QRect(0, 0, pixmap.width(), pixmap.height()
. Use this rectangle for bounding rect also. Use setPos
to move the item around the scene. Use setTransformOriginPoint(pixmap.width() / 2, pixmap.height() / 2)
to set the origin point. These coordinates are in the item coordinates, so they should point at the pixmap's center regardless of the item's position.
来源:https://stackoverflow.com/questions/19168669/settransformoriginpoint-not-working-as-expected