问题描述
我想在 Qt3DWidget 之上有一个或多个 QPushButtons 或其他小部件,但它是不可见的.不知道为什么.
I want to have one or more QPushButtons or other widgets on top of Qt3DWidget, but it is invisible. Don't know why.
在我的 mainwindow.cpp 中,我有这样的代码:
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);
当我尝试使用 QOpenGLWidget 时它起作用了,但是使用 Qt3DWindow 这个按钮总是不可见的.看起来 Qt3DWindow 是在它上面画的.
It worked when I tried to use QOpenGLWidget, but with Qt3DWindow this button is always invisible. Looks like Qt3DWindow draws on top of it.
推荐答案
我找到了原因,但我不能说我找到了解决方案.根据文档,由createWindowContainer"提供的小部件正在父窗口的所有内容之上绘制.与它处于同一位置的每个小部件都将位于其下方并且对用户不可见.
我发现将一些东西放在 Qt3D 之上的唯一方法是使用 QtQuick 和 QScene3D 编写一个应用程序.
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.
这篇关于如何将 QPushButton 放入小部件中的 Qt3DWindow?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!