Results 1 to 3 of 3

Thread: QGLWidget in QScrollArea

  1. #1
    Join Date
    Jan 2012
    Minneapolis, MN, USA
    Qt products
    MacOS X Unix/X11 Windows

    Default QGLWidget in QScrollArea

    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

    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

    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.

  2. #2
    Join Date
    Jan 2012
    Minneapolis, MN, USA
    Qt products
    MacOS X Unix/X11 Windows

    Default Re: QGLWidget in QScrollArea

    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.

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3. //#include <GL/glut.h>
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8. // glutInit( &argc, argv );
    9. MainWindow w;
    12. return a.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    4. #include <QMainWindow>
    6. #include <QDockWidget>
    7. #include <QGLWidget>
    8. #include <QScrollArea>
    10. namespace Ui {
    11. class MainWindow;
    12. }
    14. class MainWindow : public QMainWindow
    15. {
    16. Q_OBJECT
    18. public:
    19. explicit MainWindow(QWidget *parent = 0);
    20. ~MainWindow();
    22. private:
    23. Ui::MainWindow *ui;
    25. QGLWidget* gw1;
    26. QGLWidget* gw2;
    27. QGLWidget* gw3;
    28. };
    30. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    10. dw1 = new QDockWidget("DW1",this);
    11. dw2 = new QDockWidget("DW2",this);
    13. addDockWidget(Qt::RightDockWidgetArea, dw1 );
    14. addDockWidget(Qt::BottomDockWidgetArea, dw2 );
    16. sa = new QScrollArea();
    18. gw1 = new QGLWidget();
    19. gw1->setMinimumSize(100,100);
    20. dw1->setWidget(gw1);
    22. gw2 = new QGLWidget();
    23. gw2->setMinimumSize(100,100);
    24. dw2->setWidget(gw2);
    26. gw3 = new QGLWidget();
    27. gw3->setMinimumSize(1024,768);
    28. sa->setWidget(gw3);
    30. setCentralWidget(sa);
    31. }
    33. MainWindow::~MainWindow()
    34. {
    35. delete ui;
    36. delete dw1;
    37. delete dw2;
    38. delete gw1;
    39. delete gw2;
    40. delete gw3;
    41. delete sa;
    42. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Warsaw, Poland
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits

    Default Re: QGLWidget in QScrollArea

    How about this... Instead of using QScrollArea with a QGLWidget, subclass QAbstractScrollArea, and set a QGLWidget as its viewport.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.

Similar Threads

  1. Replies: 2
    Last Post: 10th March 2008, 21:16
  2. QScrollArea
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 13th December 2007, 18:20
  3. QScrollArea
    By sabeesh in forum Qt Programming
    Replies: 7
    Last Post: 2nd November 2007, 11:33
  4. QScrollArea ?
    By whitefurrows in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2007, 23:15
  5. QScrollArea
    By merry in forum Qt Programming
    Replies: 12
    Last Post: 20th June 2007, 14:05


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.