Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWebEngineView - black background QMainWindow
Qt 6.11 is out! See what's new in the release blog

QWebEngineView - black background QMainWindow

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 1.4k 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.
  • sepera_okeqS Offline
    sepera_okeqS Offline
    sepera_okeq
    wrote on last edited by sepera_okeq
    #1

    Hello there! I found a problem. Without QWebEngineView, the transparency made to create a shadow works fine for me, because my application is FramelessWindowHint.
    6519d60a-160d-45f4-8fd7-2ced894b4dfe-image.png
    or (to show that there is a shadow):
    fe6012da-0e72-4be3-948a-806d6b1674fa-image.png

    But with QWebEngineView, the place where transparency used to be is now filled with black for some reason.
    2bdd516d-5529-467c-b0ee-16826806e879-image.png

    I tried to use the solution that was presented here: https://stackoverflow.com/questions/43150506/opacity-not-working-with-qwebengineview-and-translucent-background

    But, it didn't really help, and the black area is not acceptable for me. Thank you in advance!

    1 Reply Last reply
    0
    • sepera_okeqS Offline
      sepera_okeqS Offline
      sepera_okeq
      wrote on last edited by sepera_okeq
      #2

      I decided to make a separate project for testing this thing

      Checking how transparency works with WebEngineView:

      3e9a21cd-5769-48c8-9b76-febb950fd235-image.png

      Source code:
      main.cpp

      #include "mainwindow.h"
      
      #include <QApplication>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          MainWindow w;
          w.setWindowFlags(Qt::FramelessWindowHint);
          w.show();
          return a.exec();
      }
      
      

      mainwindow.cpp

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      
      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
      
          setAttribute(Qt::WA_TranslucentBackground);
          setAutoFillBackground(true);
          ui->centralwidget->setAttribute(Qt::WA_TranslucentBackground);
          ui->webEngineView->setAttribute(Qt::WA_TranslucentBackground);
          ui->webEngineView->setStyleSheet("background:transparent");
          ui->webEngineView->page()->setBackgroundColor(Qt::transparent);
          ui->webEngineView->setUrl(QUrl("https://google.com"));
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      

      mainwindow.h

      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H
      
      #include <QMainWindow>
      
      QT_BEGIN_NAMESPACE
      namespace Ui { class MainWindow; }
      QT_END_NAMESPACE
      
      class MainWindow : public QMainWindow
      {
          Q_OBJECT
      
      public:
          MainWindow(QWidget *parent = nullptr);
          ~MainWindow();
      
      private:
          Ui::MainWindow *ui;
      };
      #endif // MAINWINDOW_H
      

      mainwindow.ui
      (where the white rectangle is a QWighet converted to a QWebEngineView)

      19ec1452-8406-4780-b5ed-3a91f075cc66-image.png

      When I deleted this wighet and deleted 4 lines of code( where WebEngineView is present), everything worked for me and it is transparent. Is it possible that this is a bug with QWebEngineView, which for some reason affects the style of the entire MainWindow?

      b6208fbc-89fc-49ab-b298-8de118ed68b3-image.png

      1 Reply Last reply
      0

      • Login

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