Important: Please read the Qt Code of Conduct -

QScrollArea with QGLWidget on Linux is completely broken

  • For background, I am trying to port my rather large project ("": from Windows to Linux. Everything works fine on Windows, but I am really disappointed at just how hard getting Qt to work/look the same on Linux has been. There are numerous other issues I've encountered, but I will save them for another post.

    My specs are:

    Linux Mint 17 x64
    Cinnamon as the UI
    Qt 5.4
    AMD video card with up to date drivers installed

    My problem is the following:

    I have a QGLWidget whose drawing area can be resized by the user. When this happens, I set its width and height via call to setFixedSize(). I then update the GL viewport, output texture size, etc.

    Since the user could conceivably want to render to a surface larger than the parent window, I have placed QGLWidget on a QScrollArea.

    This works perfectly on Windows 7 and the scrollbars appear as needed and scroll around the underlying OpenGL output window when the user drags them around.

    However, on Linux, it's completely broken any time the QGLWidget size is greater than its parent QScrollArea, making the entire idea of a scrolling area useless.

    The OpenGL output wraps around the window and what would have been drawn outside the viewable area on the right side of the window wraps around and draws over what's on the left side of the main window. In addition, there are artifacts all over the place. It gets worse when I initially show the window with showMaximized().

    I'm positive this is a Qt problem and not a video driver problem, because I am doing pretty heavy video card work with OpenGL and OpenCL and everything else works on Linux just as perfectly as it works in Windows.

    For demonstration I have distilled the problem down to a very simple program gotten from the grabber example that comes with Qt:


    Here is the basic code in the main window constructor. All it does is place a QGLWidget in a QScrollArea and sets the QGLWidget to a fixed size.

    glWidget = new GLWidget;

    glWidgetArea = new QScrollArea;

    glWidgetArea->setAlignment(Qt::AlignCenter);//This makes the drawing even more distorted, comment out for top left which is only slightly better.

    glWidgetArea->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);//Set these to anything, it doesn't matter.
    glWidgetArea->setMinimumSize(200, 200);


    //Drawing is crippled worse when doing showMaximize().
    //resize(1500, 1500);
    glWidget->setFixedSize(1000, 1000);//Make the GL widget smaller than the initial window, else it will freeze the entire OS on startup.

    I have also tried QAbstractScrollArea with no luck there either.

    For reference, I believe another person is also seeing the same thing:

    Any help with this would be greatly appreciated. If I can't figure this out, I most likely won't continue porting my project to Linux.

  • One final check to see if anyone can repro this and offer help. If not, I'll submit it as a bug.


  • Moderators


    QGLWidget is known for multiple issues when put inside complex widget hierarchies. That's why it was deprecated in Qt 5.4 in favour of QOpenGLWidget.

    Read the "documentation": to find out the differences between QGLWidget and QOpenGLWidget, then switch to QOpenGLWidget if feasible. Does that resolve your problem?

  • Thanks JKSH, I had no idea that QGLWidget was deprecated. I appreciate the heads up. I just scanned through the documentation for QOpenGLWidget and it looks like the Qt team did a good job fixing what was wrong. I will attempt the fix later and post the results here.

  • Moderators

    You're most welcome. All the best with your project!

    You might also be interested in this "Qt Weekly article": that introduces QOpenGLWidget

  • I've confirmed this fixes the problem. Works great on Windows and Linux. Thanks again.

Log in to reply