Qt 6.6.1 WebAssembly. Background color of parent window is changed to black
-
Hi,
I have a main window to place an OpenGL widget on it Background color of parent window is changed to black:
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
But it works without the problem on Desktop:
And on physical device with Android:
-
If I don't add the
openGLWidget
:QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget(m_nameLabel); // layout->addWidget(openGLWidget); layout->addStretch(); setLayout(layout);
the color is normal:
-
I created the bug report: https://bugreports.qt.io/browse/QTBUG-120651
-
@8Observer8 Did you find a workaround for this problem?
-
@andrew22 I sure it is a bug of Qt and only Qt developers can solve it. I made a bug report: https://bugreports.qt.io/browse/QTBUG-120651 I attached an example in a zip there.
I found a solution of the second problem: https://bugreports.qt.io/browse/QTBUG-120956 When you resize a window it will be completely black. You should call
glClearColor()
in thepaintGL()
method like this:void paintGL() override { glClearColor(0.1f, 0.3f, 0.2f, 1.f); glClear(GL_COLOR_BUFFER_BIT); }
You can upload WebAssembly files to sandboxes, like replit.com and an app can be running by one click: https://replit.com/@8Observer8/background-color-of-parent-window-opengl-qt6-cpp
-
@8Observer8 Thank you for your response. I'll keep an eye on the bug report.