简体   繁体   English

Qt透明QWebView:过去的页面停留在新页面的背景中

[英]Qt transparent QWebView: past page stay in background of new one

I have a little app with a transparent QWebView displaying some HTML pages (they all have a style="background-color: transparent;" property on the body) over a QTabWidget with a font. 我有显示某些HTML页面透明QWebView一个小应用程序(它们都具有一种风格=“背景颜色:透明;”对身体的财产)超过QTabWidget与字体。

The transparency is working, i can see the font of my QTabWidget beside the content of my QWebView . 透明度的工作,我可以看到我的QWebView的内容旁边我QTabWidget的字体。 But when i load another page in the QWebView , the old one is still visible in the background of the new one. 但是,当我在QWebView中加载另一页面时,旧页面仍在新页面的背景中可见。 Like if the pages were just arranged one above the other and not closed. 就像页面只是一个页面排列在另一个页面之上,而不是关闭在一起一样。

I dont know how to get rid of this behavior and from where it can come from! 我不知道该如何摆脱这种行为以及它的根源!

I had similar problem recently with QtJambi. 我最近在QtJambi遇到了类似的问题。 The page I load is dynamic (animations with javascript and css3) and the web view painted new rendering without clearing the old rendering each time some component was moving or changing. 我加载的页面是动态的(使用javascript和css3进行动画处理),并且每次移动或更改某个组件时,Web视图都绘制新的渲染,而不会清除旧的渲染。

I found a solution today. 我今天找到了解决方案。 I wrote a class inherited from QWebView and set the background to transparent in the paintEvent method. 我编写了一个从QWebView继承的类,并在paintEvent方法中将背景设置为透明。 The background is set to transparent each time the web view is repainted. 每次重新绘制Web视图时,背景设置为透明。

Here is my Java code 这是我的Java代码

    public class WebBrowserTestQWebView extends QWebView
{
    @Override
    public void paintEvent(QPaintEvent event)
    {
        QPalette palette = this.palette(); 
        palette.setBrush(QPalette.ColorRole.Base, new QBrush(new QColor(Qt.GlobalColor.transparent)));
        this.setPalette(palette); 
        this.setAttribute(Qt.WidgetAttribute.WA_OpaquePaintEvent, false);
        super.paintEvent(event); 
    }
}

I guess it works with C++ too. 我猜它也可以与C ++一起使用。

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

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