I would like to create a QPixmap to draw on using a QPainter. The QPixmap should support transparency without using premultiplied color channels.
Currently I do this by creating a QPixmap with the desired dimensions and filling it with a QColor that has been set to zero for each channel (including alpha).
tex = QtGui.QPixmap(width, height)
c = QtGui.QColor(0)
c.setAlpha(0)
tex.fill(c)
This adds transparency to the QPixmap. However, if I draw to the QPixmap using a QPainter, the drawn color values are premultiplied by the alpha value of the source. I don't want this because the QPixmap is later used as a texture in a QGLWidget and upon rendering the alpha channel of the QPixmap (now the alpha of the source that was drawn using the QPainter) is again multiplied against the color channels, so that the alpha is multiplied twice.
If I use a QImage with format QtGui.QImage.Format_ARGB32 in place of the QPixmap, then the color channels are not premultiplied and the alpha is applied only once. However this is too slow during rendering. I have tried to draw on QImages with the above format and then convert to QPixmaps, but got the same result (premultiplied color channels again being multiplied by the alpha channel). The Trolltech docs say,
Depending on the system, QPixmap is stored using a RGB32 or a premultiplied alpha format. If the image has an alpha channel, and if the system allows, the preferred format is premultiplied alpha.
I am using X (Linux). Is there any way to force a QPixmap to not premultiply the color channels when that QPixmap has an alpha channel?