Disable widget background fills before paint
-
Initial problem is flickering:
after widget resized (enlarged), exposed background is filled with some color and than control goes to custom paint function. If custom paint is slow (insert sleep(200)), there is visible transition, especially for exposed regions. I searched for solution to disable initial background fills, so delay before custom paint if invisible. The only solution that worked was setWindowFlags(Qt::FramelessWindowHint), but this is inappropriate.
Code to reproduce:@#include <QtGui>
#include <QTest>class TestScene: public QGraphicsScene {
public:
virtual void drawBackground(QPainter * painter, const QRectF & rect) {
QTest::qSleep(200);
painter->fillRect(rect, Qt::blue);
}
};int main(int argc, char *argv[]) {
QApplication a(argc, argv);
QGraphicsView w;
w.setScene(new TestScene());
w.show();
return a.exec();
}
//try to enlarge widget by mouse, see flickering with different color
@
I tried to disable background fills with many other ways, such as:
@ setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_OpaquePaintEvent);
setAttribute(Qt::WA_NoSystemBackground);
setAutoFillBackground(false);@
but debug showed that QWidgetPrivate::paintBackground is called anyway (from /src/gui/kernel/qwidget.cpp QWidgetPrivate::drawWidget).
I changed QWidgetPrivate::paintBackground so it didn't do anything. Situation became better - some artifacts became on screen, but that flickering remained. Even if no custom paint (leave only delay without printing commands), there was flickering with different colors on resize. Where can I found code which makes such fills, so I can change it? Thanks.
PS WIndows 7 64 bit, Qt 4.7.4-32 -
Perhaps, the problem you are facing is an OS problem.
If you resize a window, windows reserves the painting area. Qt itself works with double buffering, so the buffer is blit to to the screen, when all painting is done.If you trigger some repaint by your selfe, this could be a reason, but otherwise, it should not be.