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.
The transparency is working, i can see the font of my QTabWidget beside the content of my QWebView. But when i load another page in the QWebView, the old one is still visible in the background of the new one. 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. 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.
I found a solution today. I wrote a class inherited from QWebView and set the background to transparent in the paintEvent method. The background is set to transparent each time the web view is repainted.
Here is my Java code
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.