[PyQt] Pixel pushing performance
Håkon Bertheussen
haakon at bertheussen.com
Thu May 8 00:16:25 BST 2008
Hi,
I'm just getting started with PyQt, trying to implement a fairly complex
widget in python. Unfortunately, it cannot easily be painted using
higher level drawing primitives, meaning that I have to set individual
pixels. I realize that this obviously has a lot of overhead compared to
a C++ implementation, but if possible I'd like to stay in Python. Here's
what I'm doing now:
def paintEvent(self, event):
canvas = QtGui.QImage(event.rect().size(),
QtGui.QImage.Format_RGB32)
for i in xrange(0, canvas.height()):
for j in xrange(0, canvas.width()):
canvas.setPixel(j, i, 123456)
painter = QtGui.QPainter()
painter.begin(self)
painter.fillRect(event.rect(), QtGui.QBrush(canvas))
painter.end()
Obviously, in my real application the inner statement in the loop is a
bit more complex, but even the above example is slow when the widget is
fairly large (e.g. 300x300px). Is there a way to speed this up?
More information about the PyQt
mailing list