[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: More help with QpaintEvent
From:       Uwe Thiem <uwe () uwix ! alt ! na>
Date:       2000-03-07 8:45:39
[Download RAW message or body]

On Mon, 6 Mar 2000, Daniel wrote:

> I'm afraid I need a bit more help with QPaintEvent.... :-(
> 
> My app needs to read DXF files created by CAD applications and draw them
> on the screen to later add properties to the lines imported.
> This is what my paintEvent looks like:
> 
> void KonGraphic::paintEvent(QPaintEvent *){
> QPainter paint;
>  paint.begin(this);
>  paint.scale(1,-1);
>  paint.translate(0,-300);
>  paint.setPen(blue);
>  paint.setWindow(0,0,300,300);
>  KonElement *el;
>  for (el=element.first();el !=0; el=element.next())
>  el->draw(paint);
>  paint.end();
> };
> 
> element is a QStrList containing the elements imported from the DXF file
> and the draw method draws a line from begining to end coordinates of the
> element.
> 
> Now here are my doubts:
> 
> 1. Each time the mouse pointer passes over a menu entry , the drawing
> flickers, I suppose because its getting redrawn; I dont think this is
> right.WHICH could be a right way to do the paintEvent?

Don't draw on a widget directly. Instead, draw on a QPixmap (as a cache
so to say) and bitBlt that QPixmap to the widget in paintEvent(). Now,
you have got two different cases:

a)
The widget has been obscured (partly). It doesn't really need re-painting
but rather restoring. In this case you just bitBlt the existing QPixmap
to the widget in paintEvent().

b)
Some has changed (widget got resized, new elements to be drawn,...).
Somewhere in your code (*not* in paintEvent() ), you redraw the QPixmap
and then you make sure that paintEvent() gets called to copy the
QPixmap to the widget.

Voila!

> 
> 2. Next comes to implement tools that modify the drawing someway,
> however if all my painting stuff has to happen inside the paintEvent I
> suppose I should just update the elements in the QStringList and let the
> paintEvent redraw the new stuff.... is this right?

I strongly advise not to draw in paintEvent() at all, just bitBlt a
QPixmap. So if you really need to *change* the display you draw on
the QPixmap and make sure paintEvent() gets called.

Uwe

-------------------------------------------------------------------------
Uwe Thiem                                        Tel: +264 - 061 - 241223
P.O.Box 30955                                    
Windhoek                                         Email:   uwe@uwix.alt.na
Republic of Namibia                                           uwe@kde.org
                                                       http://www.kde.org
                  **********************************
         You can still escape from the GATES of hell: Use KDE!
-------------------------------------------------------------------------

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic