[英]Show Qt3D stuff inside QWidget in Qt5
因此,当我读到Qt3D重新出现在v2.0 中并且实际上很快成为Qt5的一部分并且其中的一部分已经可以作为技术预览进行测试后,我内心感到温暖和模糊。
我制定了一个简单的计划,我将让Qt3D在我现有的基于C++/widgets的应用程序中的一个小部件中工作。 然而,我能找到的唯一一个展示如何从C++使用Qt3D 的示例称为basicshapes-cpp ,它显示了在单独的 OpenGL/Qt3D 准备好的window
(扩展QWindow
类)中呈现的一些形状,而不是QWidget
。
现在我读到了QWindow
与QWidget
的作用以及QWindow
如何巧妙地结合在一起,但我仍在努力理解如何将Qt3D代码从basicshapes-cpp
程序basicshapes-cpp
到QWidget
运行。 需要观察的基本步骤是什么?
如果有人感兴趣,我实现了一个实际的 Qt3D 小部件。 代码可以在这里找到。
这种提取这篇文章显示了它是如何工作:
#include <QObject>
#include <QWidget>
#include <Qt3DExtras/Qt3DWindow>
class Qt3DWidget
: public QWidget
{
Q_OBJECT
QWidget *container;
public:
explicit Qt3DWidget(QWidget *parent = nullptr);
};
Qt3DWidget::Qt3DWidget(QWidget *parent)
: QWidget(parent)
{
auto view = new Qt3DExtras::Qt3DWindow();
// put Qt3DWindow into a container in order to make it possible
// to handle the view inside a widget
container = createWindowContainer(view,this);
// ... further stuff goes here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.