3

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.

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.

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?

Alex44
  • 3,597
  • 7
  • 39
  • 56
Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95
  • 3
    For the moment, just use `QWidget::createWindowContainer`. Proper QWidget integration should be coming in 5.8 / 5.9. – peppe Jan 29 '16 at 10:27
  • Sweet! Put it in an asnwer and I will accept it :) – Mr. Developerdude Jan 30 '16 at 03:35
  • So just to clairfy, even if there is a new QOpenGLWidget, that cannot work with Qt3D? – Mr. Developerdude Jan 30 '16 at 04:14
  • No, unfortunately, that's meant for user-provided GL code. An "equivalent" solution (i.e. a "proper QWidget") is probably easy to write, it's just going to miss the 5.7 release though. (The other piece of the puzzle missing is a way to control Qt3D rendering from the outside, i.e. have a custom driver for Qt3D and allow its integration in foreign GL code) – peppe Jan 30 '16 at 22:29
  • @peppe Are there any updates on the issue? I'm currently with Qt 5.12 at it seems there is still no solution. And no documentation :-( – Equilibrius Sep 12 '19 at 03:18

2 Answers2

4

In case anybody is interested, I implemented an actual Qt3D widget. The code can be found here.

Florian Blume
  • 3,237
  • 17
  • 37
3

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
}
Alex44
  • 3,597
  • 7
  • 39
  • 56