QScrollArea with QGLWidget on Linux is completely broken
For background, I am trying to port my rather large project ("https://github.com/mfeemster/fractorium/wiki":https://github.com/mfeemster/fractorium/wiki) 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
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.
//Drawing is crippled worse when doing showMaximize().
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.
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.
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":http://doc.qt.io/qt-5/qopenglwidget.html 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.
You're most welcome. All the best with your project!
You might also be interested in this "Qt Weekly article":http://blog.qt.digia.com/blog/2014/09/10/qt-weekly-19-qopenglwidget/ that introduces QOpenGLWidget
I've confirmed this fixes the problem. Works great on Windows and Linux. Thanks again.