Qt 6.6.1 WebAssembly中父窗口背景变黑问题求助
Qt6 WebAssembly平台添加OpenGL部件后父窗口背景变黑问题
在主窗口中添加OpenGL部件后,父窗口背景变为黑色:
相关代码如下:
main.cpp
#include <QtGui/QOpenGLFunctions> #include <QtOpenGLWidgets/QOpenGLWidget> #include <QtWidgets/QApplication> #include <QtWidgets/QLabel> #include <QtWidgets/QVBoxLayout> #include <QtWidgets/QWidget> class OpenGLWidget : public QOpenGLWidget, private QOpenGLFunctions { Q_OBJECT private: void initializeGL() override { initializeOpenGLFunctions(); } void paintGL() override { glClearColor(0.1f, 0.3f, 0.2f, 1.f); glClear(GL_COLOR_BUFFER_BIT); } }; class MainWindow : public QWidget { Q_OBJECT public: MainWindow() { setWindowTitle("OpenGL, Qt6, C++"); resize(300, 300); m_nameLabel = new QLabel("Click on object or background"); m_nameLabel->setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed); OpenGLWidget *openGLWidget = new OpenGLWidget(); QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget(m_nameLabel); layout->addWidget(openGLWidget); // layout->addStretch(); setLayout(layout); } private: QLabel *m_nameLabel; }; #include "main.moc" int main(int argc, char *argv[]) { QApplication app(argc, argv); MainWindow w; w.show(); return app.exec(); }
pro文件
QT += core gui openglwidgets widgets win32: LIBS += -lopengl32 CONFIG += c++17 SOURCES += \ main.cpp TARGET = app
现象说明
- 该问题仅出现在WebAssembly平台,桌面端运行正常:

- Android物理设备运行也正常:

- 若移除OpenGL部件(修改布局代码如下),窗口背景恢复正常:
效果截图:QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget(m_nameLabel); // layout->addWidget(openGLWidget); layout->addStretch(); setLayout(layout);
内容的提问来源于stack exchange,提问作者8Observer8
相关产品推荐
相关产品推荐

