[PyQt] Why can I rotate a GraphicsItem only once?
Philippe Crave
philippe.crave at gmail.com
Sun Aug 1 09:02:47 BST 2010
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qgraphicsitem.html#setRotation
seems that setRotation() sets an absolute value.
not an increment.
if you want to add 90°, you should do something like
self.setRotation(self.rotation()+90)
2010/8/1 Konrad Koller <koko9991 at googlemail.com>
> In a game the user should be able to rotate a GraphicsItem by clicking on
> it with the right mouse button. According the game situation he must be able
> to execute another rotation by the same angle (90°). But this time the item
> is not rotated! To explain the situation I add the essential part of my
> code:
>
> class Stone(QGraphicsPolygonItem):
> def __init__(self,polygon,brush,x,y,scene):
> QGraphicsPolygonItem.__init__(self,polygon,None,scene)
> self.setPos(x,y)
> self.setBrush(brush)
> def mousePressEvent(self,ev):
> if ev.button()==Qt.RightButton:
> print self.sceneBoundingRect()
> self.setRotation(90)
> print self.sceneBoundingRect()
>
> Two consecutive clicks produce the following output:
>
> PyQt4.QtCore.QRectF(5.0, 41.0, 90.0, 18.0)
> PyQt4.QtCore.QRectF(41.0, 5.0, 18.0, 90.0)
> PyQt4.QtCore.QRectF(41.0, 5.0, 18.0, 90.0)
> PyQt4.QtCore.QRectF(41.0, 5.0, 18.0, 90.0)
>
> This demonstrates that the second click fails and this can also be watched
> on the screen.
> What am I doing wrong? I ask for a solution because consecutive rotations
> are essential for the game.
>
> Cheers Konrad
>
> PS: For demonstration in this example the polygon is a rectangle, in other
> cases the polygons haves more edges,
>
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100801/a913a39d/attachment.html>
More information about the PyQt
mailing list