Qt5.在 QML 中嵌入 QWidget 对象 [英] Qt5. Embed QWidget object in QML

查看:184
本文介绍了Qt5.在 QML 中嵌入 QWidget 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Qt5 beta 并尝试将基于 QWidget 的对象嵌入到 QML 中.目标是尽可能多地使用 QML,并且只在 QML 不能满足我需要的情况下使用 QWidget 对象.我找到了一个解释如何在 Qt4.7 中执行此操作的链接,但我没有找到任何解释如何在 Qt5 中执行此操作的信息.

I am using Qt5 beta and trying to embed a QWidget-based object into QML. The goal is to use QML as much as possible, and only use QWidget objects where QML does not do what I need. I found a link explaining how to do this for Qt4.7, but I have not found any information explaining how to do this in Qt5.

http://doc.qt.digia.com/4.7/声明-cppextensions-qwidgets.html

同样的例子也可以在 Qt5 examples 文件夹中找到:

The same example is also available in the Qt5 examples folder under:

examples\qtquick1\declarative\cppextensions\qwidgets

examples\qtquick1\declarative\cppextensions\qwidgets

不幸的是,这个例子使用了 QtQuick 1,而不是 QtQuick 2,我想使用 Qt5 的新特性.我实际上想嵌入一个 qwt 小部件,但作为第一步,我很乐意嵌入任何简单的基于 QWidget 的对象.

Unfortunately, this example uses QtQuick 1, rather than QtQuick 2, and I would like to use the new features of Qt5. I actually want to embed a qwt widget, but as a first step I would be happy to embed any simple QWidget-based object.

谁能帮我让示例在 Qt5/QtQuick 2 下工作?

Can anybody help me get the example working under Qt5 / QtQuick 2 ?

推荐答案

Qt Quick 2 使用场景图在 GPU 上进行高效渲染.不幸的是,这使得无法将经典小部件嵌入到场景中.在 QGraphicsProxyWidget 的帮助下嵌入这些小部件的旧方法仅适用于 Qt Quick 1,因为它在内部使用 QGraphicsView 来处理所有繁重的工作,而 QGraphicsProxyWidget 是为了和它一起使用.

Qt Quick 2 uses a scene graph for efficient rendering on the GPU. Unfortunately this makes it impossible to embed classic widgets into the scene. The old approach to embed such widgets with the help of QGraphicsProxyWidget works only with Qt Quick 1, because internally it uses a QGraphicsView for all the heavy lifting and QGraphicsProxyWidget is meant to be used with it.

截至目前,我还没有计划将经典 QWidget 嵌入到我所知道的场景图中.我认为这不太可能改变,因为 QPainter 的概念、用于经典小部件的绘画框架和新的场景图不能很好地相互配合.

As of now there are no plans to enable embedding classic QWidgets into the scene graph I know of. I think this is rather unlikely to change, because the concepts of QPainter, the painting framework used for the classic widgets, and the new scene graph doesn't play well with each other.

有一些努力开发专门为 QML 需求量身定制的新小部件集,但没有一个像经典小部件一样强大和成熟.最突出的是 QML Quick Controls,从版本开始就与 Qt 捆绑在一起5.1.

There some efforts to develop new widgets sets specifically tailored for the needs of QML, but none of them are as powerful and mature as the classic widgets. The most prominent ones are the QML Quick Controls, bundled with Qt since version 5.1.

如果您真的依赖 QWT,我的建议是暂时坚持使用 Qt Quick 1.1.它仍然与 Qt 5 捆绑在一起,可能适用于像您这样的情况.但是,这样您就不会利用新的场景图.

If you really depend on QWT my advice would be to stick with Qt Quick 1.1 for now. It's still bundled with Qt 5, probably for cases like yours. That way you won't take advantage of the new scene graph, though.

这篇关于Qt5.在 QML 中嵌入 QWidget 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆