Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-94132

QWebEngine with transparent properties, other QWidget and QPushButton cannot be rendered

    XMLWordPrintable

Details

    • macOS, Windows

    Description

       QWebEngineView with transparent bg always on top

       

      //Test Code 1
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          QMainWindow mainWindow;
      
          QWebEngineView view(&mainWindow);
          view.setUrl(QUrl("https://www.baidu.com"));
          view.setGeometry(50, 50, 300, 300);
          view.page()->setBackgroundColor(Qt::transparent);
      
          QWidget overlay(&mainWindow);
          overlay.setGeometry(0, 0, 100, 100);
          overlay.raise();
          overlay.setStyleSheet("background:red");
      
          QPushButton button(&mainWindow);
          button.setGeometry(100, 0, 100, 100);
          button.setText("button");
      
          mainWindow.resize(400, 400);
          mainWindow.show();
      
          return app.exec();
      
      }
      //Test Code 2
      
      int main(int argc, char *argv[]) {
          QApplication app(argc, argv);
      
          QMainWindow mainWindow;
      
          QWebEngineView *view = new QWebEngineView(&mainWindow);
          view->setGeometry(50, 50, 300, 300);
          view->setHtml("<html><head><style>"
                        "h1 {background-color: #00ff00;}</style></head>"
                        "<body><h1>This is heading 1</h1></body></html>",
                        QUrl("http://localhost"));
      
          view->page()->setBackgroundColor(Qt::transparent);
      
          QWidget overlay(&mainWindow);
          overlay.setGeometry(0, 0, 100, 100);
          overlay.raise();
          overlay.setStyleSheet("background:red");
      
          QPushButton button(&mainWindow);
          button.setGeometry(100, 0, 100, 100);
          button.setText("button");
      
          mainWindow.resize(400, 400);
          mainWindow.show();
      
          QObject::connect(&button, &QPushButton::clicked, [ = ]() {
              static bool transparent = false;
              view->page()->setBackgroundColor(transparent ? Qt::transparent : Qt::white);
              transparent = !transparent;
          });
      
          return app.exec();
      }

      If I set "view.page()->setBackgroundColor(Qt::transparent);", the overlapping area of QWidget and QPushButton to QWebEngineView cannot be displayed.

      If I don't set "view.page()->setBackgroundColor(Qt::transparent);", I can display the overlapping area of QWidget and QPushButton to QWebEngineView.

      Attachments

        1. Test Code 1.png
          Test Code 1.png
          9 kB
        2. Test Code 1.mp4
          42 kB
        3. Test Code 2-no transparent.png
          Test Code 2-no transparent.png
          10 kB
        4. Test Code 2- transparent.png
          Test Code 2- transparent.png
          44 kB

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qt_webengine_team Qt WebEngine Team
              dashandeda Sun Moon
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes