views:

86

answers:

1

I'm trying to write a small graphic application, and I need to construct some image using PIL that I show in a widget. The image is correctly constructed (I can check with im.show()), I can convert it to a QImage, that I can save normally to disk (using QImage.save), but if I try to draw it directly on my QWidget, it only show a white square.

Here I commented out the code that is not working (converting the Image into QImage then QPixmap result in a white square), and I made a dirty hack to save the image to a temporary file and load it directly in a QPixmap, which work but is not what I want to do

https://gist.github.com/f6d479f286ad75bf72b7

Someone has an idea?

If it can help, when I try to save my QImage in a BMP file, I can access its content, but if I try to save it to a PNG it is completely white

A: 

I've done the same thing with Qt-3 using QImage.loadFromData(). I imagine it still works in Qt-4:

self.image = QImage()
if self.image.loadFromData(image_data,"PNG"):
    # image loaded successfully
Kaleb Pederson
Yeah, but my program should not use hacks like this, since PIL ImageQt.ImageQt correctly(?) converts the image to a QImage, I should be able to display it directly! I don't know why it showsas a white rect..
oulipo
`loadFromData` returns a bool indicating success or failure and allows you to specify the image format. Thus, it gives you further insight into why it's failing. If the image is correctly being loaded, there is no valid reason it should display correctly in one case but not in another. Ideally `ImageQt` will give you a valid `QImage`.
Kaleb Pederson