本文介绍了在Qt5中的QWidget中显示Qt3D内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以阅读 Qt3D 已重新出现在 v2.0 中,并且实际上很快就会成为 Qt5 的一部分其中的一部分已经可以作为技术预览版进行测试.

So I felt all warm and fuzzy inside after reading that Qt3D has re-emerged in a v2.0 and is in fact becoming a part of Qt5 soon and that parts of it is already available for testing as a tech preview.

我制定了一个简单的计划,我将使 Qt3D 在我现有的基于 C ++/widgets 的应用程序的小部件中工作.但是,我能找到的唯一显示如何使用 C ++ 中的 Qt3D 的示例称为 basicshapes-cpp ,它显示了在单独的OpenGL/Qt3D中准备的某些形状,该图像准备为window(扩展了QWindow的类),与从QWidget.

I set out with a simple plan, I would have Qt3D working inside a widget in my existing C++/widgets based application. However the only example I could find that shows how to use Qt3D from C++ is called basicshapes-cpp, and it shows some shapes rendered in a separate OpenGL/Qt3D prepared window (class that extends QWindow) as opposed from a QWidget.

现在,我了解了QWindowQWidget的关系以及它们如何巧妙地结合在一起,但是我仍在努力地理解如何从basicshapes-cpp程序在QWidget中运行.需要遵守哪些基本步骤?

Now I read about the role of QWindow vs. QWidget and how it all hangs together neatly, but I am still struggling to understand how I can port the Qt3D code from the basicshapes-cpp program to run inside a QWidget. What are the basic steps that need to observed?

推荐答案

此展示了它的工作原理:

This extraction of this post shows how it works:

#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
}

这篇关于在Qt5中的QWidget中显示Qt3D内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 02:36