Question about Qt4 and semi-transparent drawings

Zack Rusin zack at
Thu Jul 21 08:45:09 BST 2005

On Wednesday 20 July 2005 22:04, Sébastien Laoût wrote:
> Hello,
> I've done some experiments on painting with transparency with Qt3
> (like blending two images: eg. putting an image 50% opaque on top of
> another...) and that's damn slow!
> I looked at KPixmapEffect class source code and this class always
> transform the first QPixmap to a QImage, do the operations (blending
> a pixmap or image on top of another...) and then transform back the
> result to a QPixmap. But QPixmap<->QImage transformations are VERY
> slow.
> Then, I discovered QPainter::drawPixmap() can draw semi-transparent
> pixmaps on top of another.
> But that's almost as slow as using QPixmapEffect, so I suspect it to
> do the same QPixmap->QImage->QPixmap transformations.

You assumed wrong. Qt 3 does correctly composite two pixmaps with an 
alpha channel if the render extension is present. In Qt 3 we had an 
external alpha which is almost impossible to accelerate in hardware. In 
Qt 4 that changes so at least you should be hitting the most optimized 
PictOpOver case in the render code.

> Now, my question:
> Is Qt4 allow to do such blendings without having to transform twice
> the pixmaps?

Yes but so does Qt 3.

> be allowed by the X protocol... If it was the case we would already
> have optimized QPixmapEffect classe, isn't it?

Not sure what you mean here. Blending two pixmaps is hardly a special 

> How does Qt4?
> Is it as slow as before, or is painting on a QPixmap with an
> alpha-channel now as fast as if we are painting on a QPixmap without
> alpha-channel? 

The question is a little silly. You're basically asking whether a code 
path that does a lot more than some other code path will perform as 
well as the code path that does a lot less :) Unfortunately this is not 
magic, so doing more - costs more and merging pixels before outputting 
them is slower than just outputing them directly. This has nothing to 
do with Qt though.

> Does it requiere a recent version of XOrg or a 32bpp X 
> display (since QPixmap are stored on the X server side, it should be
> in 32bpp format, if I'm not wrong), or both?


> Do we need a powerful graphics card (I still don't have drivers for
> mine and am not alone, so I hope Qt4 will not requiere that) or is it
> as performant as Qt3?

Sorry, but I didn't get that question. Powerful graphics cards are not 
necessary to do fast composition at all. Drivers need to help though 
(either by implementing Exa hooks or doing it all themselves like 
NVIDIA commercial drivers do). 
If your X server is just slow at doing those operations then Qt will be 
slow. We have a lot of workarounds for code that doesn't have alpha to 
avoid render for now, but as soon as you add alpha channel to the mix 
you're depending on the fact that render works well. Of course you have 
another solution in Qt 4 and that is using the raster engine and 
painting directly on a qimage and then just pushing that image over the 


"UNIX" is never having to say you're sorry.

More information about the kde-core-devel mailing list