QSplitter/QGLWidget combination flicker on OSX
-
Hi,
I am using Qt 4.7.1 on OSX 10.6 and I am having trouble with redraw flicker when putting QGLWidget in a QSplitter.
The following code shows how to reproduce the problem.
When moving the first handle, the background (splitter/mainwindow) redraws in gray/white before the QGLWidget redraws in black.
I have added a second splitter inside the first splitter to show of this redraw latency adds up when moving the second handle.
If someone already encountered this problem and have a solution/workaround. I found nothing related on http://bugreports.qt.nokia.com
Thanks for your time.
David
main.cpp
@
// This example demonstrates a flickering problem that arise
// when combining QGLWidget and QSplitter on OSX#include <QApplication>
#include <QGLWidget>
#include <QMainWindow>
#include <QSplitter>// Uncomment this to see that QWidget does not have the same "flicker" problem as QGLWidget
//#define USE_QWIDGET// This exhibit the problem when the latency of redraw is adding up
#define USE_SUBSPLITTERclass GLWidget : public QGLWidget
{
Q_OBJECT
public:
GLWidget(QWidget *parent = 0, const QGLWidget *shareWidget = 0, Qt::WindowFlags f = 0)
: QGLWidget(parent, shareWidget, f)
{
setAttribute(Qt::WA_OpaquePaintEvent);
setAutoFillBackground(false);
}protected:
virtual void initializeGL() { qglClearColor(Qt::black); }
virtual void paintGL() { glClear(GL_COLOR_BUFFER_BIT); }
virtual QSize sizeHint() const { return QSize(800,600); }
};class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0, Qt::WindowFlags flags = 0) : QMainWindow(parent, flags)
{
setObjectName("MainWindow");
setAttribute(Qt::WA_OpaquePaintEvent);
setAutoFillBackground(false);QSplitter *splitter = new QSplitter(this);
#ifndef USE_QWIDGET
splitter->setAttribute(Qt::WA_OpaquePaintEvent);
setAutoFillBackground(false);
#endifaddWidgetToSplitter(splitter); addWidgetToSplitter(splitter);
#ifdef USE_SUBSPLITTER
QSplitter *splitter2 = new QSplitter(this);
addWidgetToSplitter(splitter2);
addWidgetToSplitter(splitter2);
splitter->addWidget(splitter2);
#endifsetCentralWidget(splitter); }
private:
void addWidgetToSplitter(QSplitter *splitter)
{
#ifndef USE_QWIDGET
splitter->addWidget(new GLWidget(splitter));
#else
QWidget *widget = new QWidget(splitter);
widget->setBackgroundRole(QPalette::ButtonText);
widget->setAutoFillBackground(true);
splitter->addWidget(widget);
#endif
}
};int main(int argc, char **argv)
{
QApplication app(argc, argv);MainWindow window; window.showMaximized(); return app.exec();
}
#include "main.moc"
@splitter.pro
@
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
QT += opengl
SOURCES += main.cpp@