在 QML 中托管 QOpenGL 小部件
我有一个库向我证明了一个 QGLWidget,并且该界面允许我仅调整大小/设置大小,并控制一些 GL 动画;但没有GL命令暴露在外,我所做的只是初始化GLWidget,然后将上下文传递给库,然后调用交换缓冲区来显示动画。
我想将此QGLWidget库集成到QML中,是否可以在其中放置一个QGLWidget QML?如果是的话怎么办?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这完全有可能!您可以编写QML插件 将 定义一个新的 QML 元素来封装库。
然后,您将从 QML 文档
导入
此插件,您将能够很好地使用新元素并利用该库提供的功能。提示:如果加载 QML 文档的应用程序设置为在 QGLWidget 上,那么您不需要在插件中创建新的 QGLWidget。 我犯过一次这个错误。
这篇博文显示如何从头开始创建简单/新的 QML 元素以及如何在 QML 文档中使用它。
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.
QGLWidget 派生自 QWidget,而 QML 小部件则实现为 QDeclarativeItem,而 QDeclarativeItem 派生自 QGraphicsObject,这两个是不同的世界。
在 QML 项目中进行 OpenGL 绘图的可能方法是声明一个新的 QDeclarativeItem,将其公开给 QML 系统,然后重写此 QDeclarativeItem 子类的绘制方法以进行本机绘画(通过调用中提供的 QPainter 实例的 beginNativePainting 和 endNativePainting绘制方法)。
看看这两个链接:
http://doc.qt.nokia.com/4.7-snapshot/qml -扩展.html
http://developer.qt.nokia.com/forums/viewthread/4109
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