PDA

View Full Version : Strange behavior of QGraphicsPolygonItem (PyQt4)



puiseux
23rd February 2013, 11:05
Hello,

I use PyQt4 4.8.4
I subclass QGraphicsPolygonItem with, say, MyGraphicsPolygonItem. In that class
each time i move, insert or delete points , in order to visualize result, i have to write :


poly = self.polygon()
poly[1]=QPointF(1.0, 2.0)#do my stuff on poly
self.setPolygon(poly)

Not very pleasant but... Going a little deeper, i notice this strange behaviour :

>>> gpol = QGraphicsPolygonItem(.....)
>>> id(gpol.polygon())
4534170912
>>> gpol.polygon()[6]
PyQt4.QtCore.QPointF(1.0, 1.0)
>>> id(gpol.polygon())
4534170128
...
and so on, id(pol) is very often changing, even when nothing happens to it.
provided id(obj) is supposed to represent memory adress of a Python object, this mean a QGraphicsPolygonItem change in place in memory...????

This does not happen with, for instance, QPointF :

>>> a = QtCore.QPointF(2,3)
>>> id(a)
4534171136
>>> a.x()
2.0
>>> id(a)
4534171136
>>> a.setY(33)
>>> id(a)
4534171136

Is this a bug ? or a desired feature ?

Thanks for your answer.