PDA

View Full Version : QGLWidget in QScrollArea



cpow
5th January 2012, 18:31
I've done a lot of Googling to try to find an answer to my question and asked several times on #qt, but to no avail. Hopefully someone somewhere can help!

My application is an IDE. It has quite a few QDockWidgets, and a tabbed center widget. Some of the QDockWidgets contain QGLWidgets. One of the tabs of the center widget contains a QScrollArea which contains a QGLWidget. Here's a screenshot when all is well:

Screenshot without problem (http://i.imgur.com/YCgt9.png)

The QScrollArea/QGLWidget of the center widget is the large graphic area in the middle. There's a docked QDockWidget and an undocked QDockWidget off to the right, each of which contain QGLWidgets rendering different things.

As you can see I've zoomed in to the QScrollArea/QGLWidget using the zoom slider such that the QGLWidget is actually much larger than the QScrollArea's viewport. All is well until I attempt to scroll to the right or down in the QScrollArea/QGLWidget. Here's what it looks like after that.

Screenshot with problem (http://i.imgur.com/8cWW0.png)

The docked QDockWidget has visible white artifacting where it was previously drawn black.

If I dock the undocked QDockWidget and do the same scrolling in the QScrollArea/QGLWidget, the same artifacting shows up in both docked QDockWidgets. If I undock either, the artifacting does not occur in the undocked QDockWidget when scrolling the QScrollArea.

I haven't found a solution to this online. I've tried using QAbstractScrollArea but I'm at a loss for what to do to get it to paint the QGLWidget.

I recently switched to using a QScrollArea to manage scrolling around the QGLWidget because it seemed cumbersome to me the way the scrolling had been implemented in the other views...which did not change the size of the QGLWidget; rather, they implemented the scrolling in the QGLWidget's paintGL.

cpow
5th January 2012, 21:23
Update: I managed to create a simple small example project with two QDockWidgets and a QScrollArea as a central widget. Even though there's not much to see in the QGLWidgets, if you scroll around in the central widget you'll see the problem I'm talking about in the docked widgets. Undock them and the flickering doesn't happen. Dock them again and scroll around and it happens.

main.cpp


#include <QtGui/QApplication>
#include "mainwindow.h"
//#include <GL/glut.h>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// glutInit( &argc, argv );
MainWindow w;
w.show();

return a.exec();
}


mainwindow.h


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

#include <QDockWidget>
#include <QGLWidget>
#include <QScrollArea>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private:
Ui::MainWindow *ui;

QDockWidget* dw1;
QDockWidget* dw2;
QGLWidget* gw1;
QGLWidget* gw2;
QGLWidget* gw3;
QScrollArea* sa;
};

#endif // MAINWINDOW_H


mainwindow.cpp


#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

dw1 = new QDockWidget("DW1",this);
dw2 = new QDockWidget("DW2",this);

addDockWidget(Qt::RightDockWidgetArea, dw1 );
addDockWidget(Qt::BottomDockWidgetArea, dw2 );

sa = new QScrollArea();

gw1 = new QGLWidget();
gw1->setMinimumSize(100,100);
dw1->setWidget(gw1);

gw2 = new QGLWidget();
gw2->setMinimumSize(100,100);
dw2->setWidget(gw2);

gw3 = new QGLWidget();
gw3->setMinimumSize(1024,768);
sa->setWidget(gw3);

setCentralWidget(sa);
}

MainWindow::~MainWindow()
{
delete ui;
delete dw1;
delete dw2;
delete gw1;
delete gw2;
delete gw3;
delete sa;
}

wysota
6th January 2012, 15:23
How about this... Instead of using QScrollArea with a QGLWidget, subclass QAbstractScrollArea, and set a QGLWidget as its viewport.