OpenGL rendering to a QML item
Asked Answered
P

1

6

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?

Pyrogenous answered 14/10, 2011 at 16:23 Comment(0)
C
3

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.

Cycle answered 16/10, 2011 at 10:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.