OpenGL rendering to a QML item

4.3k views Asked by At

I have a QML file which contains a layout of QML items and now I want one of those items to be a QGLWidget. i.e. I want to render to a specific QML item.

Is anyone aware of how to do this?

1

There are 1 answers

0
Luca Carlon On

The simplest way I suppose it to provide QML a new custom component implemented in C++. I couldn't find anything ready.

You could subclass the QDeclarativeItem and implement your OpenGL code in the paint function after using the QPainter::beginNative() function. After that you can "export" your new custom item to QML this way. This is quite simple and should work, but you'll have to setup the viewport of you QDeclarativeView to be a QGLWidget, something like this:

QDeclarativeView view;
// This is needed because OpenGL viewport doesn't support partial updates.
view.setViewportUpdateMode(QGraphicsView::FullViewportUpdateMode);
view.setViewport(new QGLWidget);

or you'll have to use the opengl graphics system for the entire application. Another way is using QML/3D.

This thread will give you some other information.