Qt - avoid white background when resizing (set background color immediately)

The question is in bold at the end, so please read this in general.

I have a widget QAbstractScrollArea

that I manually and completely render in the OnPaint () event.

In my constructor, I have set

setAttribute( Qt::WA_OpaquePaintEvent, true );
setAttribute( Qt::WA_NoSystemBackground, true );
setStyleSheet( "QWidget { background-color: rgb(0,0,77); }" );

      

and the paint event looks like this:

void MyArea::paintEvent (QPaintEvent *event) {
  QPainter view(viewport());
  view.fillRect(rect(), backgroundBrush);

  renderedPixmap = heavyAndSlowRenderingOnAPixmap();

  view.drawPixmap(viewRect, renderedPixmap, pixmapRect);
}

      

as you can see the "slow" function is being used to render the material in the pixmap.

The problem is when I resize the window, for a moment I see that the flickering white in the area is not redrawn yet

enter image description here

I know I cannot escape the white area until the viewport is redrawn, but I would like to draw that white area with the background color right away .

So the question is: Is it possible to render the background color just before the heavy-pixmap is rendered ?

I cannot find a way to achieve this. All graphics operations seem to be buffered and then immediately blended on screen together. I am using Windows 8.1 x64 and Qt5. Any way to immediately paint the background color and then continue the rest of the rendering?

+3


source to share


1 answer


A better solution would be to move the expensive rendering from paintEvent (), potentially to a different thread. You will want to cache the pixmap anyway. Update this bitmap when needed, and then call update () to trigger the redraw.



+2


source







All Articles