【发布时间】:2014-06-22 20:50:11
【问题描述】:
我正在尝试按鼠标的位置旋转 QGraphicsItem。所以在我的 Dialog.cpp 中,每当我的鼠标位置发生变化时,我都会调用这个函数:
void Dialog::rotating()
{
QPointF local = ui->graphicsView->mapToScene( ui->graphicsView->mouse );
Player->rotate(local.x(),local.y());
}
与
ui->graphicsView->setScene(scene);
和
scene->addItem(Player);
在构造函数中。
调用的旋转函数是这样做的:
void player::rotate(int x, int y)
{
double disX = x - 1100;
double disY = y - 1300;
double angle = atan2(disY, disX) * 180 / M_PI;
setTransformOriginPoint(boundingRect().center());
setRotation(rotation() + angle - orig);
orig = angle;
}
where (1100, 1300) 是玩家所在的位置。 我很确定这可以解决问题,但它不能正确旋转。也许本地位置不正确?
另外,我如何移动播放器以不影响旋转?任何输入将不胜感激。提前致谢。
【问题讨论】:
标签: c++ qt rotation qgraphicsitem