QWebEngineView - black background QMainWindow
-
Hello there! I found a problem. Without QWebEngineView, the transparency made to create a shadow works fine for me, because my application is FramelessWindowHint.
or (to show that there is a shadow):
But with QWebEngineView, the place where transparency used to be is now filled with black for some reason.
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!
-
I decided to make a separate project for testing this thing
Checking how transparency works with WebEngineView:
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)
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?