2

I want to have one or more QPushButtons or other widgets on top of Qt3DWidget, but it is invisible. Don't know why.

In my mainwindow.cpp I have such code:

this->renderer = new Qt3DExtras::Qt3DWindow(); 
this->renderer->defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d41));
this->rendererContainer = QWidget::createWindowContainer(this->renderer);
ui->centralWidget->layout()->addWidget(this->rendererContainer);

this->shotButton = new QPushButton("Make photo", this->rendererContainer);
this->shotButton->move(this->rendererContainer->width() / 2 - (this->shotButton->width()-20) / 2, this->rendererContainer->height()-40);

It worked when I tried to use QOpenGLWidget, but with Qt3DWindow this button is always invisible. Looks like Qt3DWindow draws on top of it.

1 Answers1

1

I found the reason, but I can't say that I found the solution. The widget, provided by 'createWindowContainer', is drawing on top of everything of the parent window, according to docs. Every single widget in the same position with it will be under it and invisible for user.
The only way which I found to put something on top of Qt3D is to write an app by using QtQuick and QScene3D.

  • Maybe you could ask in the Qt forums how drawing on top of the Qt3D window is achieved in QML. As far as I know there is no QScene3D C++ class so maybe they achieved this in pure QML. Then the question arises whether this is transferable to C++. – Florian Blume Aug 14 '19 at 11:44
  • Or is it maybe possible to add the button as a child of the container widget? Maybe this way you can make the button visible. – Florian Blume Aug 14 '19 at 11:45