diff --git a/GUI/main/main.cpp b/GUI/main/main.cpp
index 01640ddd0b2bb593ca45b70c28c510af077b5c16..e5e5201278176c1c3360ec22b00c0dacf9b67486 100644
--- a/GUI/main/main.cpp
+++ b/GUI/main/main.cpp
@@ -34,6 +34,13 @@ int main(int argc, char* argv[])
     if( options.enableHighDPISupport())
         QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
 
+#ifdef BORNAGAIN_OPENGL
+    // Hack to take care of OpenGL window appearance in the context of QDockWidget
+    // See http://doc.qt.io/qt-5/qopenglwidget.html#resource-initialization-and-cleanup
+    // FIXME Make correct clenup as explained in the link
+    QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
+#endif
+
     QApplication app(argc, argv);
 
     if (!options.find("with-debug"))