[PyQt] Problems with custom QGraphicsItem
Antonio Valentino
antonio.valentino at tiscali.it
Mon Jan 4 11:54:59 GMT 2010
Hi list,
I' having some problem with a custom QGraphicsItem: the option parameter seems to contain wrong values.
Using the included test code I would expect an option.levelOfDetail value of 0.5 and an option.exposedRect smaller than the entire item rect.
Running the following test cone on Mac OS X Snow Leopard I always get:
option.exposedRect PyQt4.QtCore.QRectF(0.0, 0.0, 1024.0, 1024.0)
option.levelOfDetail 1.0
Is it a bug?
# BEGIN CODE #
import sys
from PyQt4 import QtCore, QtGui
class GraphicsItem(QtGui.QGraphicsItem):
data = QtGui.QImage(':/trolltech/qmessagebox/images/qtlogo-64.png')
data = data.scaled(1024, 1024, QtCore.Qt.KeepAspectRatio)
def boundingRect(self):
return QtCore.QRectF(self.data.rect())
def paint(self, painter, option, widget):
print 'option.exposedRect', option.exposedRect
print 'option.levelOfDetail', option.levelOfDetail
exposedData = self.data.copy(option.exposedRect.toAlignedRect())
painter.drawImage(option.exposedRect, exposedData)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
w = QtGui.QGraphicsView()
w.resize(400, 300)
scene = QtGui.QGraphicsScene(w)
scene.addItem(GraphicsItem())
w.setScene(scene)
w.scale(0.5, 0.5)
w.show()
sys.exit(app.exec_())
# END CODE #
Mac OS X 10.6.2 Snow Leopard
Python 2.6.1 (system python)
sip 4.9.3
PyQt4 4.6.2
Qt 4.6.0 (cocoa 64bit)
Best regards
--
Antonio Valentino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100104/838aa4b8/attachment.html>
More information about the PyQt
mailing list