As we can see from the documentation QImage.scanLine() returns sip.voidptr object. But how to get pixels colors from this object? Reading sip documentation tells us that it has asstring(length) method, which returns length bytes from sip.voidptr position. Ok, that's enough to get colors pixel by pixel. Let's see an example:
import struct;
from PyQt4 import QtGui;
# get QImage object
# ...
#
img = img.convertToFormat(QtGui.QImage.Format_RGB32);
width = img.width();
height = img.height();
linebytes = width * 4;
for y in xrange(0, height):
pixels = img.scanLine(y).asstring(linebytes);
for x in xrange(0, width):
# unpack 32 bit integer
color = struct.unpack('I', pixels[x*4:x*4+4])[0];
# here it is
r = QtGui.qRed(color);
g = QtGui.qGreen(color);
b = QtGui.qBlue(color);