qt QGraphicsItem 绕轴旋转问题
1.我用Qt图形视图框架,对QGraphicsItem进行旋转,发现他是以屏坐标系统进行旋转的,不是以自己坐标系统旋转。2.我先把QGraphicsIte 绕Z轴平面旋转一定角度,然后再把QGraphicsItemY轴旋转。
我想以QGraphicsItem自己坐标系统旋转。但它却以标准坐标屏旋转。
有什么方法可以解决不。
以下是我的代码
resetTransform();
QTransform transformf = transform();
r += 20;
qreal x = boundingRect().center().x();
qreal y = boundingRect().center().y();
transformf.translate(boundingRect().center().x(),boundingRect().center().y() );
transformf.rotate(r, Qt::XAxis);
transformf.translate( - boundingRect().center().x(),-boundingRect().center().y() );
setTransform(transformf); --------------------编程问答-------------------- boundingRect().center()返回的本来是你在scene中的坐标,不知道你这段代码写在哪里的,QGraphicsItem::paint( )函数本来就有一个参数是QPainter,而QPainter可以执行旋转放大缩小和平移操作,为什么不使用它呢? --------------------编程问答-------------------- 把你这个对象先移动到0.0点。然后旋转。
然后再移回去~ --------------------编程问答-------------------- 楼上正解.
translate(x,y).rotate(r).translate(-x,-y)
补充:移动开发 , Qt