我编写了以下代码,将bullet旋转为enemy:

void Bullet::turnToFutureLocation(Enemy *enemy)
{
    QLineF ln(mapToScene(rect().topLeft()), enemy->mapToScene(enemy->rect().topLeft()));
    setRotation(ln.angle());
}
bulletenemy都从QGraphicsRectItem派生。
运行代码时,我的项目符号不在屏幕上。
当我尝试使用给定参数旋转它时,会发生以下情况:
setRotation(0);

c++ - Qt-更改QGraphicsRectItem的旋转中心-LMLPHP
setRotation(10);

c++ - Qt-更改QGraphicsRectItem的旋转中心-LMLPHP
不仅仅是旋转,bullet围绕场景的原点旋转。
我怎样才能使其旋转?

最佳答案

函数setTransformOriginPoint()更改旋转中心。
默认中心始终为0,0。

来源:http://doc.qt.io/qt-4.8/qgraphicsitem.html#setRotation

10-07 13:38
查看更多