[PyQt] Problem with QGraphicsView and Scale

Cyril Giraudon cyril.giraudon at free.fr
Mon Jul 9 16:11:31 BST 2012


My system is win7 and I use PyQt version 4.8.5 on Qt 4.7.3.
Seems there is a bug with QGraphicsView and scaling capability.

Consider the script below. It is a simple circle in a view.
The program can take a parameter : 1 <= the scale <= 1000 (for instance).

When scale = 1 (python script.py 1),  the circle is selected only when 
the circle is clicked.
When scale = 1000 (python script.py 1000),  the circle is selected when 
the mouse is in the top left quart plane relative to the circle
x < 0
y < 0

Is this a known issue ?

Best regards,


# script.py [scale]
# -*- coding: utf-8 -*-

import sys

from PyQt4.QtCore import Qt
from PyQt4.QtGui import (QApplication, QGraphicsScene,
                          QGraphicsView, QGraphicsEllipseItem,
                          QPainter, QBrush)

class Circle(QGraphicsEllipseItem):
     def __init__(self, parent=None):
         super(Circle, self).__init__(-50., -50., 100., 100., parent=parent)
     self.setFlag(self.ItemIsSelectable , True)
     self.setFlag(self.ItemIsMovable, True)

if __name__ == "__main__":
     from PyQt4.QtCore import QT_VERSION_STR, PYQT_VERSION_STR
     print "PyQt version : ", PYQT_VERSION_STR
     print "Qt version : ", QT_VERSION_STR
     app = QApplication(sys.argv)

     scale = float(sys.argv[1]) if len(sys.argv)>1 else 1.

     scene = QGraphicsScene()
     fc = Circle(parent=None)

     view = QGraphicsView(scene)
     view.scale(scale, scale)


More information about the PyQt mailing list