- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个QGraphicsItem ( self .rb)。我想使用 QGraphicsRotation 围绕一个点(self.originPoint)旋转这个项目。但是当我尝试执行下面的代码时,它给出了如下所示的错误。有人可以帮忙吗?
in canvasMoveEvent self.rb.setTransform(rotationItem) TypeError: QGraphicsItem.setTransform(QTransform, bool combine=False): argument 1 has unexpected type 'QGraphicsRotation'
Python version: 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]
代码:
def canvasPressEvent(self, event):
self.rb = QgsRubberBand(self.canvas, True)
self.originPoint = self.rb.boundingRect().center()
if self.rb:return
def canvasMoveEvent(self,event):
if not self.rb:return
currpoint = self.toLayerCoordinates(self.layer,event.pos())
angle = center.azimuth( currpoint )
rotationItem = QGraphicsRotation()
rotationItem.setAngle = angle
rotationItem.setOrigin = QVector3D(self.originPoint)
self.rb.setTransform(rotationItem)
最佳答案
QGraphicsItem.setTransform()函数需要 QTransform作为它的第一个参数。让你措手不及的是 QGraphicsRotation不是 QTransform!它处于不同的层次结构中;它继承自QGraphicsTransform ,继承自 QObject .
所以你不能传入 QGraphicsRotation 来旋转你的 QGraphicsItem,这是违反直觉的。您必须创建一个 QTransform 来执行您想要的操作,并使用它。
或者 - 这可能更容易 - 使用 QGraphicsItem.setRotation()和 QGraphicsItem.setTransformOriginPoint()函数来应用您所需的转换,而无需担心自己创建任何转换对象。
希望有帮助!
关于python - 如何在 QGraphicsItem 上使用 QGraphicsRotation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14155465/
我是一名优秀的程序员,十分优秀!