Bug 29414 - [Qt] [Regression] Transparent QWebView
Summary: [Qt] [Regression] Transparent QWebView
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: Other OS X 10.5
: P2 Normal
Assignee: QtWebKit Unassigned
URL:
Keywords: Qt, QtTriaged
Depends on:
Blocks: 35784
  Show dependency treegraph
 
Reported: 2009-09-18 07:36 PDT by Tor Arne Vestbø
Modified: 2010-05-18 13:27 PDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tor Arne Vestbø 2009-09-18 07:36:09 PDT
This bug report originated from issue QTBUG-3706
<http://bugreports.qt.nokia.com/browse/QTBUG-3706>

--- Description ---

The result of the code below is a fully-transparent background in the HTML page, so that one can overlay it over an existing widget background. This worked in Qt 4.4.3, but not anymore in 4.5.0. The page renders with a solid white background instead.

Test case (needs an image):
//----------------------------------------------------

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QWidget *widget = new QWidget;
    widget->setStyleSheet("QWidget {background: url(background.png)}");
    QVBoxLayout *vbox = new QVBoxLayout(widget);
    QWebView *webView = new QWebView;
    vbox->addWidget(webView);
    QPalette p = webView->palette();
    p.setColor( QPalette::Dark, Qt::transparent );
    webView->setPalette(p);
    p = webView->page()->palette();
    p.setColor( QPalette::Window, Qt::transparent );
    webView->page()->setPalette(p);
    webView->setHtml("<body style='background: rgba(0,0,0,0)'>"
"<h1 style='color:white'>Test</h1></body>");
    widget->show();
    return a.exec();
}
//----------------------------------------------------

--- Comments ---

Note: qtuser: 03/09/09 03:32:05 PM:
Here's a fix/workaround for this issue:

The difference between Qt 4.4 and 4.5 is that in Qt 4.4, the background is first filled with QPalette::Dark by the QWebView followed by QPalette::Window by the QWebPage.  In Qt 4.5, the page background is only filled with the QPalette::Base color.  Making that color transparent in the palette of the QWebView allows the page to be transparent again.  However, a small change to the Qt source is also necessary in order for painting to work properly:

In the file src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp, in QWebView::setPage(), remove the following line:

setAttribute(Qt::WA_OpaquePaintEvent, d->page);

I would say the 4.5 behavior is better.  It's just different from 4.4 -- but maybe nobody else was doing transparent QWebViews, so I'd rather stick with the 4.5 behavior (with the above fix).
Comment 1 Jesus Sanchez-Palencia 2010-05-14 07:29:46 PDT
Blocking 2.0 just until we confirm if this is a regression or not.
Comment 2 Simon Hausmann 2010-05-18 13:27:37 PDT
This is indeed intentional. The opaque paint event flag by default allows for optimizations in Qt. It's easy to disable it from the application side in the rare case the webview is meant to be transparent:

http://labs.trolltech.com/blogs/2009/06/30/transparent-qwebview-or-qwebpage/