views:

31

answers:

2

HI all,

The following code:

self.painter = QtGui.QPainter(self)
self.painter.setRenderHint(QPainter.Antialiasing)
self.painter.translate(482,395)
self.painter.scale(300,300)
self.painter.save()
needle = Qt.QPolygon([QPoint(30, 0), QPoint(-30, 0), QPoint(0, 200)])
self.painter.setBrush(Qt.cyan)
self.painter.setPen(Qt.black)
self.painter.drawPolygon(needle)
self.painter.restore()

is causing my Pyqt application to crash. Does anyone have any idea why? It is part of my ui_form.py file which was automatically spat out by pyuic4. Removing / commenting it out fixes the problem. Yes, I wrote this myself instead of the compiler doing it.

Many thanks!

+1  A: 

Save the list which you pass the the constructor of QPolygon in a local variable. I guess that the elements get garbage collected as soon as the call returns so when you draw the polygon, they are no longer around.

points = [QPoint(30, 0), QPoint(-30, 0), QPoint(0, 200)]
needle = Qt.QPolygon(points)
Aaron Digulla
Thanks for your answer Aaron, unfortunately even after making that change I am getting the error:
Emile Victor
TypeError: arguments did not match any overloaded call: QPainter(): too many arguments QPainter(QPaintDevice): argument 1 has unexpected type 'Dash'
Emile Victor
err.. what is "self"?
Aaron Digulla
A: 
Prof.Ebral
Also, you have QPolygon from QtCore.Qt ... since when is the QPolygon a part of the QtCore.Qt libraries? It's a part of QtGui in 4.6. I am surprise that does not fail.
Prof.Ebral