Qt旋转/移动自定义项目相对于鼠标
Qt Rotating/moving custom item relative to mousepos
我正在尝试通过鼠标的位置旋转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);
构造函数中的。
rotate函数的作用如下:
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;
}
,其中(1100,1300)是玩家所在的位置。我很确定这能起作用,但它没有正确旋转。也许是当地的位置不对?
另外,我如何移动播放器,使旋转不影响它?任何意见将不胜感激。提前感谢。
花了我一些时间,但我终于弄明白了!
函数rotate(int,int)的第一行应该是:
double disX = x - (1100 + boundingRect().center().x());
double disY = y - (1300 + boundingRect().center().y());
相关文章:
- unique_ptr相对于shared_ptr的优势是什么
- int 相对于C++中主代码的目的
- SourceAddress 是否相对于 MmCopyVirtualMemory 中的 SourceProcess?
- 对于我在 Microsoft Visual C++ IDE (2005 或更高版本)的本机 win32 项目中编写的应用
- 现代C++的实验特征对于长期项目是否可靠?
- 对于大型C/C++项目,在编译时使用GNU m4
- 相对于类statics的基元全局的生存期
- 实现现有的网络接口,以相对于C 11中的Endianess定义位字段
- 如何添加相对于QTABBAR中标签的位置的小部件
- 相对于 3D 应用程序中的 Windows 消息循环的计时错误
- §12.3.2 [class.conv.fct]/1 in C++1z 相对于 C++14 发生了重大变化。有意义吗?
- 对于C++项目,从Gradle移动到CMake
- 相对于 cpp 不工作目录的路径
- 使用原生C++Qt相对于PyQt有什么优势?
- 打开相对于chromium.exe的文件
- msvcr100相对于msvcrt的优势
- at()函数相对于get(ch)的必要性
- unique_ptr相对于auto_ptr的优点
- c++中std::thread相对于pthread的优势
- 哈希,相对于x,y位置的多边形