PDA

View Full Version : How to enable transparency (composition) of QGraphicsItems



aarpon
11th April 2008, 09:49
Hello

First of all, greetings to everybody since I am new in the forum.

I have a question on how to enable composition of QGraphicsItems.

In my QGraphicsScene I paint several QGraphicsItems that the user can then drag around. If one item is dragged over another I would like to be able to see the one in the background through the one that is being dragged (and is in the foreground). I guess I should somehow enable composition. I got this working if the two items were rendered on top of a QPixmap, but I do not know how to do it if I am rendering on a QGraphicsScene.

Does the z value of the items in the scene also play a role?

I would appreciate any help on this.

wysota
11th April 2008, 10:32
You don't have to enable anything. You only need to use colours that are not fully opaque (with alpha values less than max). In case of pixmaps you'll have to set some masks on them (unless they already have them).

aarpon
11th April 2008, 12:42
Thanks a lot, it worked.

Just one more question: how do you set the alpha channel of a QImage? If for instance I create a QImage from let's say a TIFF file, how can I then set its alpha value?

wysota
11th April 2008, 13:25
QImage::setAlphaChannel, QImage::createHeuristicMask, QImage::createAlphaMask, QImage::createMaskFromColor. Pick one that suits you best.