Reimplement QGraphicsItem setRotation and setScale methods with QTransform
Unsolved
Qt for Python
-
Hello all. I am trying to reimplement the
setRotation
andsetScale
methods of my qgraphicsitem with a QTransform.So far, I have this:
def setRotation(self, angle): self._rotation = angle self.updateTransform() def setScale(self, scale): self._scale = scale self.updateTransform() def rotation(self): return self._rotation def scale(self): return self._scale def updateTransform(self): # Compute the custom transformation transform = self.transform() transform.translate(self.boundingRect().center().x(), self.boundingRect().center().y()) transform.rotate(self._rotation) transform.scale(self._scale, self._scale) transform.translate(-self.boundingRect().center().x(), -self.boundingRect().center().y()) self.setTransform(transform)
The major issue is how the transforms stack on top of each other, causing the problem where trying to reset the rotation/scale to
0
doesn't change anything. This means if I rotate the item to45
and try to then rotate it back to0
, nothing happens because the item transform is already at0
for rotation.Any help is greatly appreciated.
-
Hi,
As silly as it may sound: why not start from a fresh transform ?