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

QWebEngine with transparent properties, always on top. other QWidget and QPushButton cannot be rendered

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • None
    • 5.15.6, 5.15.2, 6.2.0
    • WebEngine
    • None
    • macOS, Windows

    Description

      QWebEngineView with transparent bg always on top. I want to display the QWidget overlay and QPushButton button on the QWebEngineView.

      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.

       

      //代码占位符
      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();
      }
      

      Attachments

        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:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes