[Qt-interest] Xor'ing in paint event

Ender EREL erelender at yahoo.com
Wed Aug 26 15:42:00 CEST 2009


Hi Folks,

I have a Base class and a Derived class. Both have to do some painting 
in their paint events.

In the derived class, i want my drawings to be xor'ed with the drawings 
of the base class.

Since the documentation clearly says "Warning: You can only set the 
composition mode for QPainter objects that operates on a QImage.", I 
tried a workaround.

I tried grabbing the drawings of my base widget using 
QPixmap::grabWidget((Base*)this), then convert the result to a QImage, 
then construct a QPainter with the image and 
setCompositionMode(CompositionMode_Xor), and then do my drawings onto 
that image and finally draw this image to the widget. Since just 
explaining that method took this long, i don't think it is an elegant 
solution. Also it doesn't work because QPixmap::grabWidget((Base*)this) 
causes a stack overflow.

Anyone have any ideas on how to achieve this? Or any leads on where to 
start?

Thanks in advance.

-- 
Ender EREL



More information about the Qt-interest-old mailing list