[PyQt] Strange problem with QPixmap

David Cortesi davecortesi at gmail.com
Fri Oct 7 07:05:27 BST 2011


I've a working program that loads grayscale PNG images with QPixmap.
The call is the simplest possible,

    pxmap = QPixmap(pngPathString)

This worked great, but recently I got a set of png images that look
fine in Mac OS Preview, in Photoshop, etc. but when loaded with the
above, the colors are inverted, black for white. (Incidentally, they
also display with inverted color when loaded in Summerfield's chapter
6 example program "imagechanger.py") When I load one image in
Photoshop and save it (making no changes), that image now looks
correct when loaded with my code (or Summerfield's).

To analyze this I want to experiment with the other parameters of
QPixmap, especially the flags = Qt.AutoColor one, but the crazy thing
is, now I cannot find any combination of explicit parameters that
works. I tried

pxmap = QPixmap(pngPathString,b"PNG",Qt.AutoColor)
pxmap = QPixmap(pngPathString,b"png",Qt.AutoColor)
pxmap = QPixmap(pngPathString,None,Qt.AutoColor)
pxmap = QPixmap(pngPathString,format = None, flags = Qt.AutoColor)
pxmap = QPixmap(pngPathString,"PNG") # that won't work with unicode literals...
pxmap = QPixmap(pngPathString,None)

and several others but the only variation that actually succeeds is
the minimal one. So now I have two stupid puzzles, one, why do some
.png's load with inverted color, and b, what is the actual signature
of QPixmap (and its .load method)?

Any suggestions appreciated.

Dave Cortesi


More information about the PyQt mailing list