View Full Version : QImage, PNG ad Transparency

6th May 2011, 09:32

I'm new to the forum and quite new to the Qt Programming.

I've a problem with QImage.
I need to draw an image (.png) with transparency.
I've serched and read a lot of thread on this forum, but I did'nt found any solution.

This is the code I used to load the image:

imm=QImage(53,48,QImage::Format_ARGB32_Premultipli ed);
immGL=QImage(53,48,QImage::Format_ARGB32_Premultip lied);

imm.load("image.png", "PNG");
immGL = QGLWidget::convertToGLFormat(imm);

This is the code to draw the image:

glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, immGL.bits());

As a result, the image is drawn with all pixel that should be transparent converted to black.

Any solutions?

Thanks in advance,

6th May 2011, 13:39
This is not the fault of QImage but rather of the way you use it. Either your image.png doesn't contain transparency or information about it is lost in OpenGL. And first two lines of your first code snippet can be discarded as lines #4 and #5 respectively will overwrite the objects created earlier.

6th May 2011, 14:41
Ok, thanks.
I will check OpenGL options.

14th May 2014, 08:52
Hi, I've the same issue, did you solved it?
What did you did?


30th May 2014, 07:26
hi i am very new to QT please help me on Immage reading(raw immage) from QT using QgraphisScreen as base calss and derived method from QGLWidget ... if provide me sample code or URL Thanks in advance ....

30th May 2014, 07:41
QImage img("path/to/image");