PDA

View Full Version : Drawing a QPixmap transparently with QPainter



ComServant
11th October 2010, 00:07
Problem:

I have a QPixmap that already has an alpha channel. I want to use QPainter to drawPixmap() a QPixmap, but I want to draw it halfway transparent. I do not want to edit the QPixmap itself, unless I can easily undo the edit... thousands of times a frame.

---------------------------------
Scenario:

Basically, I already have a QGraphicsScene with plenty of transparent QPixmaps, but I want to temporarilly draw a number of them (but not all) transparently, in response to the user's actions.

---------------------------------
Question:

Can I get QPainter to transparently draw a QPixmap?

Something like: painter->drawPixmapTransparently(x, y, pixmap, transparency

Or:

Can I temporarily adjust the alpha of an entire QPixmap image, without permanently adjusting it's alpha channel?

Something like: pixmap->setAlpha(128)

---------------------------------

I've looked through the documentation (ofcourse), but I can't seem to find what I'm looking for. Since I'm not too familiar with QT, I'm hoping I've just overlooked the feature somewhere.

Thank you in advance!

ChrisW67
11th October 2010, 02:33
QPainter::setOpacity() perhaps?

ComServant
11th October 2010, 23:10
Yes, thank you, that was exactly what I was looking for. I was looking for 'alpha', and 'transparency'... but it was named 'opacity'. =)

Other APIs have similar, so I figured I must've just been overlooking it somewhere.

Thanks again, Chris, I apreciate the help.