我的问题是:我有一个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
定义变换原点,QGraphicsItem::setRotation
旋转项目。