Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. Qt 6.6.1 WebAssembly. Background color of parent window is changed to black

Qt 6.6.1 WebAssembly. Background color of parent window is changed to black

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
6 Posts 2 Posters 543 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 8 Offline
    8 Offline
    8Observer8
    wrote on 30 Dec 2023, 15:07 last edited by 8Observer8
    #1

    Hi,

    I have a main window to place an OpenGL widget on it Background color of parent window is changed to black:

    0438b7f9-f707-45d1-a2ba-6a0c6054a431-image.png

    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:

    d7d1c670-10f8-457d-88e4-fba3e1421a39-image.png

    And on physical device with Android:

    af1ab982-2c89-44b6-badf-63c7c155a4ac-image.png

    Cross-ref: https://stackoverflow.com/questions/77736353/qt-6-6-1-webassembly-background-color-of-parent-window-is-changed-to-black

    1 Reply Last reply
    0
    • 8 Offline
      8 Offline
      8Observer8
      wrote on 30 Dec 2023, 15:16 last edited by
      #2

      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:

      f6105fee-39d8-4080-8f48-26a5336c6417-image.png

      1 Reply Last reply
      0
      • 8 Offline
        8 Offline
        8Observer8
        wrote on 8 Jan 2024, 23:02 last edited by
        #3

        I created the bug report: https://bugreports.qt.io/browse/QTBUG-120651

        A 1 Reply Last reply 15 Jan 2024, 17:09
        1
        • 8 8Observer8
          8 Jan 2024, 23:02

          I created the bug report: https://bugreports.qt.io/browse/QTBUG-120651

          A Offline
          A Offline
          andrew22
          wrote on 15 Jan 2024, 17:09 last edited by
          #4

          @8Observer8 Did you find a workaround for this problem?

          8 1 Reply Last reply 15 Jan 2024, 17:46
          0
          • A andrew22
            15 Jan 2024, 17:09

            @8Observer8 Did you find a workaround for this problem?

            8 Offline
            8 Offline
            8Observer8
            wrote on 15 Jan 2024, 17:46 last edited by 8Observer8
            #5

            @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 the paintGL() 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

            A 1 Reply Last reply 15 Jan 2024, 18:32
            0
            • 8 8Observer8
              15 Jan 2024, 17:46

              @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 the paintGL() 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

              A Offline
              A Offline
              andrew22
              wrote on 15 Jan 2024, 18:32 last edited by
              #6

              @8Observer8 Thank you for your response. I'll keep an eye on the bug report.

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved