PDA

View Full Version : Are transparent QPixmaps possible?



eric
19th November 2007, 20:31
Hello.
I would like to display one pixmap over another (using QLabels) so that both pixmaps show. The bottom pixmap is a bmp image from a file, the top one is a circle.
When I display the circle over the bmp image (using the code below), the background of the circle is going to cover part of the bmp. I don't want that. I want the circle pixmap to be transparent so that I only get the circle on top on the pixmap and none of the circle's background. Would someone be able to suggest how to modify the below code to make that happen.
I know you are going to say that I should first display my bmp file as a pixmap and then draw the circle on the same pixmap, but I wonder if this can be done with two pre-existing pixmaps.



mainLayout = new QVBoxLayout;
pixmapLabel = new QLabel;
drawLabel = new QLabel(pixmapLabel);;

QPixmap pm(600,450);
pm.load("image.bmp");
pixmapLabel->setPixmap(pm);

QPixmap pm4(100,100);
QPainter p4(&pm4);
QPen pen4(Qt::white, 3);
p4.setPen(pen4);
p4.drawEllipse(10, 10, 50, 50);
drawLabel->setPixmap(pm4);

mainLayout->addWidget(pixmapLabel);
setLayout(mainLayout);

marcel
19th November 2007, 20:43
mainLayout = new QVBoxLayout;
pixmapLabel = new QLabel;
drawLabel = new QLabel(pixmapLabel);;
QPixmap pm(600,450);
pm.load("image.bmp");
pixmapLabel->setPixmap(pm);

QPixmap pm4(100,100);
pm4.fill(Qt::Transparent); // add this!
QPainter p4(&pm4);
QPen pen4(Qt::white, 3);
p4.setPen(pen4);
p4.drawEllipse(10, 10, 50, 50);
drawLabel->setPixmap(pm4);
mainLayout->addWidget(pixmapLabel);
setLayout(mainLayout);