gpt4 book ai didi

c++ - Qt - 改变 QGraphicsRectItem 的旋转中心

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:44:41 26 4
gpt4 key购买 nike

我编写了这段代码来将 bullet 旋转到 enemy:

void Bullet::turnToFutureLocation(Enemy *enemy)
{
QLineF ln(mapToScene(rect().topLeft()), enemy->mapToScene(enemy->rect().topLeft()));
setRotation(ln.angle());
}

bulletenemy 都派生自 QGraphicsRectItem

当我运行我的代码时,我的项目符号不在屏幕上。
当我尝试使用给定参数旋转它时,会发生这种情况:

setRotation(0);

Graphical Representation

setRotation(10);

enter image description here
bullet 不是仅仅旋转,而是围绕场景的原点旋转。
我怎样才能让它旋转?

最佳答案

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

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

关于c++ - Qt - 改变 QGraphicsRectItem 的旋转中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41380243/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com