Search code examples
qtrotationqpixmapqtranslate

QPixmap xAxis Rotation


I want to rotate a pixmap from its xAxis, but it just rotates from top left corner.(I want it to be rotated from the center) here is my code:

QTransform *X = new QTransform();
X->translate(pixmap().size().width() / 2, pixmap().size().height() / 2);
X->rotate(rtn, Qt::XAxis); //rtn is an angle
setTransform(*X);

It seems that the translate method does not change the origin point to the center of my pixmap. Now I want some help to solve this problem.


Solution

  • ok, the problem was that I didn't translate back my transformation after rotate method, this is the appropriate rotation from center on xAxis:

    setTransform(QTransform().translate(pixmap().size().width() / 2, pixmap().size().height() / 2).rotate(rtn, Qt::XAxis).translate(-pixmap().size().width() / 2, -pixmap().size().height() / 2));