[英]Transparent Background in QWebEnginePage
We are trying to port some application from Qt 4 to Qt 5.4. 我们正在尝试将一些应用程序从Qt 4移植到Qt 5.4。 The Qt 5.4 has a new web engine.
Qt 5.4有一个新的Web引擎。 We used to make the background of
QWebView
and QWebPage
to be transparent: 我们曾经使
QWebView
和QWebPage
的背景透明:
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 doesn't work for QWebEngineView
and QWebEnginePage
. 但是这段代码不适用于
QWebEngineView
和QWebEnginePage
。 The point is that QWebEnginePage
doesn't have such an API like setPalette
. 关键是
QWebEnginePage
没有像setPalette
这样的API。
Can anyone find a way to solve this? 谁能找到解决这个问题的方法?
As mentioned in https://bugreports.qt.io/browse/QTBUG-41960 , this is now working by simply using this line: 如https://bugreports.qt.io/browse/QTBUG-41960中所述 ,现在只需使用以下行即可:
webEngineView->page()->setBackgroundColor(Qt::transparent);
I've tried it in Qt 5.6 and it works well. 我在Qt 5.6中尝试过,它运行良好。
Update : In order to make this answer more helpful, let me show all relevant code. 更新 :为了使这个答案更有帮助,让我展示所有相关的代码。
In MainWindow, I have set this: 在MainWindow中,我设置了这个:
setAttribute(Qt::WA_TranslucentBackground);
setAutoFillBackground(true);
setWindowFlags(Qt::FramelessWindowHint);
For the webEngineView
object, I have set these attributes: 对于
webEngineView
对象,我设置了以下属性:
webEngineView->setAttribute(Qt::WA_TranslucentBackground);
webEngineView->setStyleSheet("background:transparent");
webEnginePage = webEngineView->page();
// https://bugreports.qt.io/browse/QTBUG-41960
webEnginePage->setBackgroundColor(Qt::transparent);
I hope it helps. 我希望它有所帮助。
No. A partial solution has been committed to upstream, but it covers only QtQuick and you can't have any elements on top: 没有。部分解决方案已经提交到上游,但它只涵盖了QtQuick,你不能拥有任何元素:
https://bugreports.qt.io/browse/QTBUG-41960 https://bugreports.qt.io/browse/QTBUG-41960
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.