From kde-devel Tue Mar 07 08:45:39 2000 From: Uwe Thiem Date: Tue, 07 Mar 2000 08:45:39 +0000 To: kde-devel Subject: Re: More help with QpaintEvent X-MARC-Message: https://marc.info/?l=kde-devel&m=95241873903729 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! -------------------------------------------------------------------------