简体   繁体   English

为QWebView设置透明背景

[英]Setting transparent background for QWebView

I am trying to set transparent background to a QWebView element. 我试图将透明背景设置为QWebView元素。

+---------------------------+
| x | Window title          | <<< Hidden borders and title bar
+---------------------------+     view->setWindowFlags(Qt::FramelessWindowHint);
|                           |
|     ******************    |   
|    ********************<--|------- This is the HTML side (a rectangle with
|     ******************    |        rounded corners)
|                         <-|-- with transparent background that must
+---------------------------+   remain transparent for the desktop window

I searched about how can I set the transparent background for the webview and I found this code on all places: 我搜索了如何设置webview的透明背景,我在所有地方都找到了这个代码:

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

The code above doesn't work properly. 上面的代码无法正常工作。 This is how my window does look: 这就是我的窗口看起来的样子:

So, the issue is that the gray part MUST be transparent. 所以,问题是灰色部分必须是透明的。 How can I solve this? 我怎么解决这个问题?

I use the following code to undecorate the window. 我使用以下代码来undecorate窗口。

view->setWindowFlags(Qt::FramelessWindowHint);

This works for me : 这对我有用:

view->setStyleSheet("background:transparent");
view->setAttribute(Qt::WA_TranslucentBackground);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM