PDA

View Full Version : QPixmap::grabWidget and QWidget::render loose alpha



EricF
6th March 2008, 14:56
I'm doing transparency on my widget and when trying to render it in a QPixmap or QImage, the alpha is lost. QPixmap::hasAlphaChannel returns true but the actual alpha channel is full opaque.

The transparency works for the widget on the screen but not in the QPixmap.

Any hint ?

kernel_panic
7th March 2008, 08:45
erm.... you render the image into a pixmap. the widget itself has no background, with which it coul be transpariced(haha, dont know if this word exists, hope you understand what i mean).
if you want transparency, render the parent widget and draw the child onto it.

EricF
7th March 2008, 15:37
Yeah it makes sense however it doesn't work. In fact if I only render the region of the parent widget that shows my widget, the transparency gets applied in the child widget but the alpha channel of the resulting pixmap is still full opaque.

I wouldn't mind if the actual rendering was full opaque but would like to get my alpha channel good.

EricF
7th March 2008, 15:47
Well ... I finally made it. It appears that (I still don't know why though) QPixmap can't do it but using a QImage with Format_ARGB32 format, the widget renders opaque but the alpha channel it returns is the right one.

kernel_panic
10th March 2008, 09:14
hm... could you attach some code?
i would like to test it here.

mchara
11th March 2008, 09:42
hi,
i think you just need no prepare a pixmap on which you are drawing widgets

QPixmap pix;
pix.fill(QColor(0,0,0,0));
If you are drawing items with transparency on something that is non transparent you'll see parts of old images contents on places where widgets are transparent so you need to draw them on transparent pixmap.