setTransformOriginPoint不能按预期工作 [英] setTransformOriginPoint not working as expected

查看:213
本文介绍了setTransformOriginPoint不能按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从QGraphicsObject继承并创建了一个新的类,该类具有一个pixmap,并将其变换原点设置为:

I inherited from the QGraphicsObject and created a new class that has a pixmap and sets its transform origin point to:

setTransformOriginPoint(boundingRect().center());

但是当我在班级上调用setRotation()时(使用场景将其添加到QGraphicsView中),旋转不会使用中心作为旋转锚点.如何设置中心作为旋转的锚点?谢谢!

But when I call setRotation() on the my class (which is added to a QGraphicsView using the scene), the rotation doesn't use the center as the rotation anchor. How can I set the center to be the anchor of the rotation ? Thanks !

更多信息:在场景事件函数外部调用setRotation()可以工作,但是在场景事件内部,按捏手势时,原点不起作用.

More information: calling setRotation() outside of a sceneEvent function it works, but inside a sceneEvent, upon a pinch gesture, the origin point doesn't work.

推荐答案

QRect(0, 0, pixmap.width(), pixmap.height()处绘制像素图.也可以使用此矩形作为矩形的边界.使用setPos在场景中移动项目.使用setTransformOriginPoint(pixmap.width() / 2, pixmap.height() / 2)设置原点.这些坐标位于项的坐标中,因此无论项的位置如何,它们都应指向像素图的中心.

Draw pixmap at QRect(0, 0, pixmap.width(), pixmap.height(). Use this rectangle for bounding rect also. Use setPos to move the item around the scene. Use setTransformOriginPoint(pixmap.width() / 2, pixmap.height() / 2) to set the origin point. These coordinates are in the item coordinates, so they should point at the pixmap's center regardless of the item's position.

这篇关于setTransformOriginPoint不能按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆