PDA

View Full Version : Transparent Pixmap



maverick_pol
19th December 2007, 15:16
Hi,

I am currently working a bit with the QPixmap class. I am looking for a solution how to create a transparent pixmap. I need to create a QGraphicsPixmapItem and add it to the scene.
I am drawing different symbols( created from rects,polygons,lines <- describing shapes). For example, I would like to add 5 circles to the pixmap and only show those circles on the scene, as they were simple Items, not pixmaps.(in some cases these symbols will be much more complicated)
Transparency of a pixmap is the issue. By transparency I mean -> transparent background of the pixmap(no background). If I would not add anything to the pixmap and then painted it, nothing would be shown,etc.

Thank you for any help.

Kacper

marcel
19th December 2007, 15:20
Try:


pixmap.fill(Qt::Transparent);

but right after you open a painter on the pixmap, not before.

maverick_pol
19th December 2007, 15:28
Thanks.

Kacper

maverick_pol
19th December 2007, 15:56
Ok,

Is this code, what you mean?



QPixmap world(100,100);
QPainter painter(&world);
world.fill(Qt::transparent);
painter.setPen(Qt::black);
painter.setBrush(QBrush(Qt::black));
painter.drawRect(QRectF(QPointF(0,0),QPointF(50,50 )));
iworld.save("C:/world.png","PNG");


while adding the "world.fill(Qt::transparent)" the whole pixmap is transparent(in the meaning of being empty)

What am I doing wrong or is there a flow in your answer?
I can set Brush as Qt::transparent and it fills the rect with no colors(that's ok), but what about the other part of the pixmap? I am currently looking for the answer.

Thanks for any further help.

Kacper

EricF
19th December 2007, 16:08
Ok,
while adding the "world.fill(Qt::transparent)" the whole pixmap is transparent(in the meaning of being empty)

What am I doing wrong or is there a flow in your answer?
I can set Brush as Qt::transparent and it fills the rect with no colors(that's ok), but what about the other part of the pixmap? I am currently looking for the answer.

Thanks for any further help.

Kacper

What do you mean by the whole pixmap is transparent, you don't see the rect you're drawing afterward ?

maverick_pol
19th December 2007, 16:11
I can't see anything. The whole pixmap is transparent, as if nothing been drawn.
world.png file and world2.png (the pixmap is filled with red):

maverick_pol
19th December 2007, 16:25
Ok, I suppose I have the solution:



....
QPixmap world(100,100);
world.fill(Qt::transparent);
QPainter painter(&world);
...




..right after you open a painter on the pixmap, not before.

That was a bit misleading.

Thank you all for help.

Kacper