开发者

OpenGL rendering to a QML item

开发者 https://www.devze.com 2023-04-13 06:15 出处:网络
I have a QML file wh开发者_运维技巧ich 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.

I have a QML file wh开发者_运维技巧ich 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号