[PyKDE] question re QImage.setPixel in PyQt3

Phil Thompson phil at riverbankcomputing.co.uk
Fri Mar 10 18:01:39 GMT 2006


On Friday 10 March 2006 5:36 pm, Tony Willis wrote:
> Hi
>
> I'm using PyQt3.13 and have run across a problem with the
> python interface to the QImage setPixel method.  You can see this
> directly by replacing line 90 of examples3/desktop.py
> image.setPixel(x,y,(x+y)%128)
> by
> image.setPixel(x,y, qRgb(x,y,0))
>
> this will result in error messsages such as
> Image::setPixel: index=-16050688 out of range
>
> A call to Qimage.setColor with a qRgb object does work.
>
> The problem is that the setPixel method is expecting an
> unsigned int - the call in the original demo will work
> because (x+y)%128 will not get near the sign bit for a
> python int, whereas  qRgb(x,y,0) can return an unsigned
> value > the range of a python int.
>
> I see that qimage.sip has void setPixel(int,int,uint);
> whereas it has void setColor(int,QRgb);
>
> Thanks for any advice on how to get around this problem.

This isn't a PyQt problem. From the Qt docs...

"If the image is a paletted image (depth() <= 8) and index_or_rgb >= 
numColors(), the result is undefined."

Phil




More information about the PyQt mailing list