Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL rendering to a QML item

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?

like image 671
Chenna V Avatar asked Oct 14 '11 16:10

Chenna V


1 Answers

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.

like image 121
Luca Carlon Avatar answered Oct 07 '22 15:10

Luca Carlon