[Qt-interest] If Opacity Less than 1, QImage Not Painted

Samuel Rødal samuel.rodal at nokia.com
Thu Oct 28 17:36:00 CEST 2010


On 10/27/2010 04:31 PM, ext Josiah Bryan wrote:
> I've got a really weird problem here:
>
> QImage image((const
> uchar*)byteArray.constData(),size.width(),size.height(),QImage::Format_RGB32);
> painter->setOpacity(0.5);
> painter->drawImage(rect, image);
>
> This draws NOTHING. Not a white square, nothing - background visible at
> that location. However, if I take out the 'setOpacity' line or set it to
> 1.0, then the image draws fine. What in the world could be causing this?
>
> If I call image.convertToFormat(QImage::Format_ARGB32) prior to
> painting, it paints correctly with partial opacity - BUT this adds
> another 5ms latency to the painting - quite unacceptable, really. I need
> to paint it without having to call converToFormat just to get partial
> opacity.
>
> For the record, this is in a QGraphicsItem with a QGLWidget as the
> QGraphicsView viewport - BUT, I've also tested it without the QGLWidget
> viewport, and same problem.
>
> The image data is coming from a V4L2 capture interface using the
> V4L2_PIX_FMT_BGR32 pixel format - this works just fine, the image
> displays correctly. I just can't get it to paint with a partial opacity.
>
> Any ideas, anyone?
>
> Thanks!
> -Josiah Bryan

Format_RGB32 expects that the alpha channel of each pixel is always 
0xff, as it sometimes uses the same rendering paths as 
Format_ARGB32_Premultiplied when opacity is set.

You probably need to bitwise or each source pixel with 0xff000000.

--
Samuel




More information about the Qt-interest-old mailing list