我正在开发基于 Qt5 webview 的应用程序,我需要使 webview 中的特定颜色透明或具有 alpha 通道。例如,加载到 webview 中的网页可能具有带背景颜色的全屏 div(大多数情况下为黑色,但可能是另一种颜色)。我需要使这种颜色(带有 webview 本身)是半透明的。申请表上的所有其他元素都应通过此 web 视图可见。
问问题
491 次
1 回答
1
我想我理解你的问题,你想让 WebView 具有半透明的背景(或其他东西)。
您可以尝试删除 webview 的背景,使用这个(来源:https ://gist.github.com/anonymous/103126 ):
QPalette palette = ui->webView->palette(); //Get webView palette
palette.setBrush(QPalette::Base, Qt::transparent);
ui->webView->page()->setPalette(palette); //Set transparent palette
ui->webView->setAttribute(Qt::WA_OpaquePaintEvent, false);//Remove opaque
在您的 css 文件(到 html 中)中,使用以下命令:
<html>
<head>
body {
background-color: rgba(255, 0, 0, 0.2);//Edit "0.2" to obtain the opacity needed.
}
</head>
<body>
Something...
</body>
</html>
于 2014-08-06T18:59:18.517 回答