[PyQt] QGraphicsPolygonItem / porting from QCanvas to QGraphicsScene
Michael Krauss
hippodriver at gmx.net
Wed Jan 21 13:38:53 GMT 2009
Hello list members,
i am porting a program from PyQt3 to PyQt4. It formerly used QCanvas
and QCanvasView. Now i am using QGraphicsScene and QGraphicsView.
I replaced QCanvasPolygonalItem with QGraphicsPolygonItem but its
constructor doesn't work as expected.
The old code:
class GuiVertex(QCanvasPolygonalItem):
'''
Graphical representation of a vertex
'''
def __init__(self, text, canvas):
QCanvasPolygonalItem.__init__(self, canvas)
[...]
The new code:
class GuiVertex(QGraphicsPolygonItem):
'''
Graphical representation of a vertex
'''
def __init__(self, text, canvas):
QGraphicsPolygonItem.__init__(self, canvas)
[...]
The error message:
[mickraus at gandalf src]\$ python gui.py
Traceback (most recent call last):
File "gui.py", line 420, in <module>
main()
File "gui.py", line 414, in main
gui = Gui()
File "gui.py", line 343, in __init__
self.board.addVertex(str(v), x, y)
File "gui.py", line 221, in addVertex
vertex = GuiVertex(text, self)
File "gui.py", line 157, in __init__
QGraphicsPolygonItem.__init__(self, canvas)
TypeError: argument 1 of QGraphicsPolygonItem() has an invalid type
According to the manual
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qgraphicspolygonitem.html
the constructor expects a QGraphicsItem. As GuiVertex is a (sub)^4class
of QGraphicsItem I don't understand the TypeError. The second argument
passed to QGraphicsPolygonItem.__init__ in line 221 is of type
"class Board(QGraphicsScene)".
Kind regards,
Michael Krauss
More information about the PyQt
mailing list