Hosting QOpenGL widget inside QML
Asked Answered
F

2

8

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 ?

Fictitious answered 11/2, 2012 at 18:32 Comment(0)
M
4

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.

Mighty answered 26/2, 2012 at 3:1 Comment(2)
Hi Karl, thanks for tip, let me give a try to this today... :)Fictitious
Thx, it's fixed.Mighty
I
2

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

Ifill answered 23/2, 2012 at 13:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.