PDA

View Full Version : clean with transparent color



Lele
13th August 2006, 16:47
Hi,
I have a custom Widget where I reimplement paintEvent in order to perform custom drawing, now I'm trying in some particular situation to clean all the previous drawing operation, so I'd like to refill all the widgets with a transparent brush, but when doing that I still see all the old drawings, what can I do?

thanks

jpn
13th August 2006, 17:09
Call update() so that a paint event gets scheduled. Then just don't draw anything in paintEvent(). Any "previous drawings" aren't buffered. You must be either drawing them in the paintEvent() or the paintEvent() doesn't get even called..

Lele
14th August 2006, 08:19
thanks for replying,
well, I just thought there was some way to have "transparent paint" which helps in repaint operations, I tried with Composition mode but without success.
thanks again

jpn
14th August 2006, 08:32
well, I just thought there was some way to have "transparent paint" which helps in repaint operations, I tried with Composition mode but without success.
Child widgets are transparent by default in Qt 4.1 and later. You can get transparent brushes and pens by constructing them with a QColor with an appropriate alpha-channel (http://doc.trolltech.com/4.1/qcolor.html#alpha-blended-drawing).

pherthyl
15th August 2006, 22:37
Or using Qt::transparent

QPainter paint;
paint.setBrush(Qt::transparent);

Lele
16th August 2006, 09:20
Thank was my first try but it doesn't clean what I painted before

pherthyl
16th August 2006, 20:58
Ah, now I understand what you are saying. You're drawing something in the paintevent and then later in that same event you want to erase it back to transparent. Since the widget is capable of being transparent (since it is at the start of your paintevent), I would suspect that this is somehow possible, but I don't know exactly how. You could try having a look at some of the functions for setting the background mode.

But the better question to ask is, if there are some situations which require a transparent widget, then why don't you detect this at the start of the paintevent before drawing anything? It will be faster since you're not doing unnecessary drawing and makes this whole question irrelevant.

Lele
17th August 2006, 21:50
That's exactly what I mean, any tips on that or some workaround?
thanks again

niko
28th October 2007, 12:14
I do have exactly the same problem.

Painting with a transparent pen doesn't help (as it paints over the existing image)

and there is only a QPainter::eraseRect

thanks,
niko

wysota
28th October 2007, 13:45
Use composition mode QPainter::CompositionMode_Clear.