[Qt-interest] Xor'ing in paint event
Ian Thomson
Ian.Thomson at iongeo.com
Wed Aug 26 16:13:36 CEST 2009
Hi,
You can probably use QPainter redirection. Check out
http://doc.trolltech.com/4.5/qpainter.html#setRedirected for info.
The basic idea would be: in your derived paintEvent, you create a
QPixmap and then redirect "this" (the current widget) to the pixmap.
Then you call Base::paintEvent(event); to run the base's paint event.
After that you undirect the painter and you should have your pixmap as
desired.
I haven't tried this but it sounds like what you need.
Cheers,
Ian.
Ender EREL wrote:
> Ian Thomson wrote:
>> Hi
>>
>> This causes a stack overflow because calling the paintEvent is virtual,
>> meaning that calling it on your 'this' pointer will call
>> derived->paintEvent, even if you cast your this pointer to a Base type.
>> So you're calling the function recursively forever, overflowing the stack.
>>
>> A better solution would be to add a function to the base class called
>> 'draw' which takes a QPainter*. In the base class paintEvent, just make
>> a QPainter in the standard way, and call the draw function. In the
>> derived class, open a QPainter on an appropriately sized QImage, and
>> then pass that along to the draw function.
>>
>> Cheers,
>> Ian.
>>
>
> At first i thought of that too, but the base class is from a library
> that another team at my company is developing therefore i am trying to
> find a solution that does not require modifying the base class.
>
> Best Regards.
More information about the Qt-interest-old
mailing list