Transparent Background in QWebEnginePage

We are trying to port an application from Qt 4 to Qt 5.4. Qt 5.4 has a new web engine. We used the background of QWebView and QWebPage be transparent:

 view = new QWebView(this); QPalette palette = view->palette(); palette.setBrush(QPalette::Base, Qt::transparent); view->page()->setPalette(palette); view->setAttribute(Qt::WA_OpaquePaintEvent, false); 

But this code does not work for QWebEngineView and QWebEnginePage . The fact is that QWebEnginePage does not have an API like setPalette .

Can someone find a way to solve this problem?

+5
source share
2 answers

As mentioned in https://bugreports.qt.io/browse/QTBUG-41960 , now it works, just using this line:

 webEngineView->page()->setBackgroundColor(Qt::transparent); 

I tried this in Qt 5.6 and it works well.

Refresh . To make this answer more useful, let me show all the relevant code.

In MainWindow, I installed this:

 setAttribute(Qt::WA_TranslucentBackground); setAutoFillBackground(true); setWindowFlags(Qt::FramelessWindowHint); 

For the webEngineView object webEngineView I set these attributes:

 webEngineView->setAttribute(Qt::WA_TranslucentBackground); webEngineView->setStyleSheet("background:transparent"); webEnginePage = webEngineView->page(); // https://bugreports.qt.io/browse/QTBUG-41960 webEnginePage->setBackgroundColor(Qt::transparent); 

Hope this helps.

+5
source

Not. A partial solution was taken for the upstream, but it only covers QtQuick, and you cannot have any elements on top:

https://bugreports.qt.io/browse/QTBUG-41960

0
source

Source: https://habr.com/ru/post/1212071/


All Articles