簡體   English   中英

為QWebView設置透明背景

[英]Setting transparent background for QWebView

我試圖將透明背景設置為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

我搜索了如何設置webview的透明背景,我在所有地方都找到了這個代碼:

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

上面的代碼無法正常工作。 這就是我的窗口看起來的樣子:

所以,問題是灰色部分必須是透明的。 我怎么解決這個問題?

我使用以下代碼來undecorate窗口。

view->setWindowFlags(Qt::FramelessWindowHint);

這對我有用:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM