围绕一个点在 QGraphicsScene 上旋转 QPixmap

Rotate QPixmap on a QGraphicsScene around a point

我的问题如下: 我有一个 QGraphicsScene,上面有一个 QPixmap。我想围绕一个中心点旋转那个像素图,实际上会像时钟一样工作。

我试过这些:í

QPixmap pointer_pixmap("/home/peter/desktop/myimg2.png");
QTransform transform;

QGraphicsPixmapItem *pointer = new QGraphicsPixmapItem(pointer_pixmap);
pointer->setOffset(174,190);
pointer->setTransformOriginPoint(QPoint(174-pointer_pixmap.width(), 190-pointer_pixmap.height()));


transform.translate((174-pointer_pixmap.width())/2,(190-pointer_pixmap.height())/2);
transform.rotate(60);
transform.translate(-((174-pointer_pixmap.width())/2),-((190-pointer_pixmap.height())/2));

pointer_pixmap = pointer_pixmap.transformed(transform);

item->addItem(pointer);

pointer->setPixmap(pointer_pixmap);

看起来翻译对我的像素图没有任何影响。这是为什么?

您应该旋转 QGraphicsPixmapItem,而不是像素图本身。 使用 QGraphicsItem::setTransformOriginPoint to define the transform origin point and QGraphicsItem::setRotation 旋转项目。