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

John McClurkin jwm at nei.nih.gov
Thu Oct 28 13:35:02 CEST 2010


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?
> 

Opacity is controlled by the alpha channel. From your email, it seems 
that the original data is in RGB format. The convertToFormat adds the 
alpha channel that partial opacity needs.



More information about the Qt-interest-old mailing list