I have a rectangular image (i.e. 1280 x 1024) that I need to rotate around its central point and then translate to a given point.
In a widget paintEvent method, that's what I do:
def paintEvent(self, event):
# self._center are the coordinates where I want to set the rotated image's center.
t = QtGui.QTransform()
s = self._pm.size() # self._pm is the image to rotate.
t.translate(s.width() / 2, s.height() / 2)
t.rotate(self._degrees)
t.translate(-s.width() / 2, -s.height() / 2)
# now my image is properly rotated. Now I need to translate it to the final
# coordinates.
t.translate (self._center.x, self._center.y)
p = QtGui.QPainter(self)
p.setTransform(t)
p.drawPixmap(0, 0, self._pm)
p.end()
And that's fine with rotation. Problem is that I can't find a way to display my image with a new center, it only works if self._degrees is 0.
If I apply another translate to the QTransform object and self._degrees is not 0, the image is never centered where I'd expect it to be.
Could somebody point me to the right direction, please?
Edit
PS: I forgot to mention that the new center's coordinate are based on the original image's coordinates, not on the rotated image's ones.
If I understand you correctly
self._centercontains information where center of rotation should be placed. In such case it is quite simple to do:Remember that
setTransformset transformation of painters coordinate system.