Search code examples
openglqt4qmlqglwidget

Hosting QOpenGL widget inside QML


I have a library proving me a QGLWidget, and the interface allow me to only to resize/set size, and control some GL animation; but no GL command is exposed outside, all i do it initialize GLWidget, and then pass the context to library and later call swap buffer to show animation..

I want to integrate this QGLWidget library into QML, is it possible to hove a QGLWidget inside QML ? if yes how ?


Solution

  • It's totally possible! You can write a QML plugin that will define a new QML element to encapsulate the library.

    Then you will import this plugin from the QML document and you'll be good to use the new element and harness the features that the library offers.

    Tip: if the application that loads your QML document was setup to have it's on QGLWidget, then you won't need to create a new QGLWidget inside your plugin. I did this mistake once.

    This blog post shows how to create a simple/new QML element from scratch and how to use it in a QML document.