Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 356
P M Avatar asked Feb 11 '12 18:02

P M


2 Answers

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.

like image 184
karlphillip Avatar answered Sep 28 '22 05:09

karlphillip


QGLWidget derives from the QWidget while QML widgets are implemented as QDeclarativeItem which derives from QGraphicsObject and these two are to different worlds.

Possible way of doing OpenGL drawings in a QML item is to declare a new QDeclarativeItem, expose it to the QML system and then override the draw method of this QDeclarativeItem subclass to do native painting(by calling the beginNativePainting and endNativePainting of the QPainter instance provided in the draw method).

Have a look at these two links: http://doc.qt.nokia.com/4.7-snapshot/qml-extending.html http://developer.qt.nokia.com/forums/viewthread/4109

like image 33
rgngl Avatar answered Sep 28 '22 07:09

rgngl