Hey, not sure if you found the solution yet. But you can try this:
QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem;
pixmapItem->setPixmap(QPixmap(":/images/pixmap.png"));
_scene->addItem(pixmapItem);
pixmapItem->setRotation(pixmapItem->rotation() + 45.0);
QGraphicsRectItem *boundingRect = new QGraphicsRectItem(pixmapItem->sceneBoundingRect());
QPen outlinePen;
outlinePen.setWidth(2);
outlinePen.setColor(Qt::red);
boundingRect->setPen(outlinePen);
_scene->addItem(boundingRect);
I believe what you want is the sceneBoundingRect() and not the boundingRect().
@michelmadeira said in How to rotate a Pixmap around bottom, right corner?:
How to change anchor point of a pixmap rotation?
By modifying your QTransform to set 0/0 to the bottom right corner because the Qt coordinate system starts with 0/0 in the upper left.
@houmingc You took that example straight from the documentation page for Rotation, which shows a picture of exactly what will happen. What more do you need? "Default angle" makes no sense. If you don't specify one there will be no rotation. It rotates around the origin along the axis. If you still don't understand, make a quick example and play around with it.
you can try this :
https://github.com/sunnyfulin/TankWar.git
a little game, almost the same with yours. not finished yet.
use keys: w , s , a , d to move the tank and mouse to control the turrent direction, and mouse's left button click to fire a bullet.
mouse's right button pressed for locking the turrent direction.
First of all while(1) in a UI thread is a very bad idea. This effectively freezes your ui.
A quick fix is to add qApp->processEvents(); at the end of the loop, but that's really just a band-aid.
Instead of the loop I would suggest to start a timer at reasonable interval (not shorter than an average monitor can actually display). You wouldn't need the processEvents hack with that.
Another thing is that you're loading an image, setting painter hints and recreating two pixmaps and a painter every step of the animation. That's terribly inefficient. Take them all out of the loop and just redo the painting, not the whole shabang.