PDA

View Full Version : QPixmap, PNG and Transparency



jsmax
2nd December 2010, 03:53
Hi. I have a QPixmap object loaded from a PNG file with transparency. This pixmap is displayed onto a QGraphicsScene via an overloaded QGraphicsItem.

I want the item to be more "lighty" when it is selected. I'm doing something like this:



painter->fillRect(boundingRect(), Qt::gray);
painter->setCompositionMode(QPainter::CompositionMode_Overl ay);
QRect rect = boundingRect().toRect();
painter->drawPixmap(rect, myPixmap);


It's working, but the problem is that the transparent region of the pixmap becomes "grayed" too ...

How can i draw the gray color just on the real icon, not touching the transparent region of the pixmap ?

high_flyer
2nd December 2010, 08:53
some ideas that come to mind:
a. you can have a look at the effect classes see if you find something there
b. you can have a light and dark version of your image in two pixmaps
c. you can set a mask to your pixmap if its not changing size.

jsmax
2nd December 2010, 13:19
The first idea is what i wanted. Now using the QGraphicsOpacityEffect class.

Thanks a lot :)