Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render a Qt3d view as a widget on QApplication MainWindow

Tags:

c++

widget

qt

qt3d

I'm starting out in Qt. I'm trying to render a 3D view from Qt3d on the MainWindow of a QApplication.

The examples I've found are all based on QGuiApplications without widgets using Qt Quick and QML but I'm aiming to use widgets since this is going to be a desktop application.

I have used Qt designer for my MainWindow UI form, On the central widget I have used Vertical layout to place tabs on my left and an empty widget with expansive horizontal size policy on the right. My goal is to create a Class that is based on an existing Qt class that will support Qt3d while also being able to handle widgets. Then from the Mainwindow form I want to promote the Widget to that class.

I've tried QWindow but it doesn't allow widgets, am I suppose to Use QGlview to get access to the widgets?I'm not really looking to mess with opengl and isn't that deprecated now? Can someone direct me to an example that implements this?

Thank you

like image 975
Nuno Bártolo Avatar asked May 22 '16 20:05

Nuno Bártolo


1 Answers

If you want to use a QWidget then the easiest way is to create a Qt3DWindow and convert it into a QWidget using createWindowContainer. You can use the returned QWidget like any other (add it to layouts or whatever).

Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow();
QWidget *container = QWidget::createWindowContainer(view);

The only problem with this approach is that it isn't quite so straightforward to use Qt Designer. I tend to just use a placeholder QWidget in Qt Designer and then use code like the above in the MainWindow constructor to create the required QWidget and either replace my placeholder or put this new widget inside the placeholder widget

like image 51
Bill Sellers Avatar answered Oct 22 '22 01:10

Bill Sellers