PDA

View Full Version : how to clean data in qimage with transparent?



rolandsun
8th June 2012, 03:52
I want to draw a real time scan radar image on widget with background terrian data, so I want to clean previous data to no color with transparent to show background correctly , I try to use codes as following


QColor qclr=QColor(Qt::tansparent);
painter->setPen(qclr);
painter->setBrush(qclr);
painter->drawConvexPolygon(pg);


but it does not works, previous data are not cleared. if I replace color with Qt::gray ,it works but I can not see the background .

I have read the post http://www.qtcentre.org/threads/3310-clean-with-transparent-color , it seem that there was no solution at that time ,how about now ?

thanks

Ginsengelf
8th June 2012, 07:16
Hi, probably the data is not "cleared" because you paint above it with a transparent brush, so you can see through the newly painted pixels and see the old data.

Have you tried wysota's solution from the other thread (set QPainter::QPainter::CompositionMode_Clear)?

Ginsengelf

wysota
8th June 2012, 21:47
What is the painter object working on? Is it a pixmap, a widget or what?

rolandsun
11th June 2012, 04:11
painter works on QImage.

wysota
11th June 2012, 07:47
Why don't you just create an empty QImage and draw on that instead of clearing the one you have?

rolandsun
12th June 2012, 02:18
In my case, I have to update the image every serveral milliseconds, only part of the image should be erased and repainted. so I think create a new QImage is infeasible.

wysota
12th June 2012, 09:02
In that case you should indeed use Clear composition mode.

rolandsun
13th June 2012, 03:40
Finally QPainter::CompositionMode_Source works ,thanks.