c++qtrotationqpixmapqgraphicspixmapitem

How to rotate an QGraphicsPixmapItem in Qt


I am trying to rotate an image in Qt. If you try this game, you can easily see how the arrow is rotating: https://www.friv.com/z/games/killcovid19/game.html?Desktop-x-x-w-x-x-xx

Assuming my image is in a QGraphicsPixmapItem, how should I make it rotate?


Solution

  • First, you need to set the rotation point (bottom-right/left in your case)

    void QGraphicsItem::setTransformOriginPoint(qreal x, qreal y)
    

    And then perform a rotation around the transform point

    void QGraphicsItem::setRotation(qreal angle)