PDA

View Full Version : how to merge QPixmaps



tommy
26th March 2008, 21:52
Hello,

I have 3 QPixmaps and I'd like to merge them (put them on top of each other). What's the best way to do that?
So, I have 3 images (A,B,C) and I want to make 1 composite image (D) out of the three.
I want to define that A is the bottom image, B is the middle image and C is the top image.
So, C should get the highest priority. If parts of C are transparent, only then should the corresponding part of B show. And if C and B are both transparent, only then should the corresponding parts of A show. Just like in real life when you stack images that have transparent regions.
I'm pretty sure that I have seen a sample code here in this site (and the code was elegantly simple) but I just can't find it again.
I'm thankful for any ideas.

yogeshm02
27th March 2008, 05:20
Painting all three pixmaps on a new one should do it, Right?

montuno
27th March 2008, 12:02
look this: http://www.qtcentre.org/forum/f-qt-programming-2/t-making-icon-with-more-than-one-image-7485.html

My solution is a bit different but I'm quite happy with


QIcon icon1(":/Resources/Icon1.png");
QPixmap icon2(":/Resources/Icon2.png");
QPixmap pixmap= icon1.pixmap(QSize(32,32));

// paints a midget of icon2 onto icon1
icon2 = icon2.scaled(QSize(12,12),Qt::KeepAspectRatio, Qt::SmoothTransformation);
QPainter painter(&pixmap);
painter.drawPixmap(0,pixmap.height()-icon2.height(),icon2);
ui.btnImage->setIcon(pixmap);