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

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

      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();
      }
      

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

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

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes