[PyQt] Why can I rotate a GraphicsItem only once?

Konrad Koller koko9991 at googlemail.com
Sun Aug 1 08:23:24 BST 2010


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,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100801/3fae93f4/attachment.html>


More information about the PyQt mailing list