Extending QtQuick.Controls ApplicationWindow to set OpenGL format
-
Hello everyone,
I am trying to write a simple OpenGL desktop application using QtQuick with QtQuick.Controls. In particular I want to make use of the MenuBar, StatusBar, ToolBar etc. features defined in ApplicationWindow, in addition to an OpenGL view. It seems like I need to set the OpenGL format before (or during) my Window class is instantiated.
My question is how do I set the OpenGL format (to OpenGL 3.3 Core Profile) without extending a QQuickWindow class (which is used by ApplicationWindow in QML I think) and doing this in the constructor. Alternatively, is it possible to link ApplicationWindow to a C++ class somehow so I can provide a custom constructor. Is there a initialization callback where I can set the format?I am using the QQmlApplicationEngine to process the main QML file. Maybe I need to use another QML engine?
Any help is greatly appreciated!
Thank you!
-
I doubt there's an easy way to accomplish this. The surface format that is normally used (via QWindow::setFormat) to request a certain OpenGL version and profile is not exposed to QML and therefore there probably is no way to set it when creating windows from QML.
You could experiment with keeping the ApplicationWindow hidden (visible: false), invoking some C++ code that calls setFormat() on it and then making it visible explicitly. If you can access the ApplicationWindow element from C++, a qobject_cast<QQuickWindow *> should give you the instance on which setFormat() can be called.
-
Using ApplicationWindow stuff is very convenient. It's unfortunate that one can't change their OpenGL version/profile when using it. This seems like a very typical use case for desktop application developers using OpenGL.
I hope this will be fixed in a future version of Qt.Thank you for the suggestion!