How to put QPushButton into Qt3DWindow which is in the widget?

て烟熏妆下的殇ゞ 提交于 2021-01-28 04:03:43

问题


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:


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.



来源:https://stackoverflow.com/questions/57450523/how-to-put-qpushbutton-into-qt3dwindow-which-is-in-the-widget

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!