QGraphicsWebView - how to set the background color that is used when the background of the page is transparent?
-
Before filing this as a bug I decided to post here to make sure that I am not missing anything.
On maemo5 some web sites will show with a black background on QGraphicsWebView. The same code will show with a white background on windows. Also the same page will show a white background when displayed on a QWebView. It happens to quite a few web sites (iphone optimized versions of amazon.com and gmail for example).
I don't know if it is just a matter of setting the background color for the scene to be white (standard for most web sites). If that is the case, how can I accomplish that?
The code used to reproduce the "issue":
@
#include <QtGui/QApplication>#include <QGraphicsScene>
#include <QGraphicsWebView>
#include <QGraphicsView>
#include <QWebPage>class WebPage : public QWebPage
{
public:
WebPage() {}protected:
virtual QString userAgentForUrl(const QUrl &url ) const {
Q_UNUSED(url);
return QString("Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7C97d Safari/528.16");
}
};int main(int argc, char *argv[])
{
QApplication app(argc, argv);WebPage page; QGraphicsScene *pScene = new QGraphicsScene(); QGraphicsView *pView = new QGraphicsView(pScene); pView->setFrameShape(QFrame::NoFrame); QGraphicsWebView *pWebview = new QGraphicsWebView(); pWebview->setPage(&page); pWebview->setResizesToContents(true); pWebview->load(QUrl("http://www.amazon.com")); pScene->addItem(pWebview); pView->show(); return app.exec();
}@
On windows it will look like expected (white background) but on maemo/n900 will have a black background.
-
I think you just need to set the palette to something a bit more standard. The maemo palette is rather different than usual, with black backgrounds for most elements.
Using the system palette for webpages works great on desktop but not so much on devices where you have such strange styles. We are working on a special style for mobile for the future versions of QtWebKit.
The theme is in themeQtMobile.css on WebKit trunk if you are interested.
-
Benjamin,
Thank you. Your suggestion led me to http://doc.qt.nokia.com/qt-maemo/maemo5-graphicswebview.htmladding these two lines before line #30 did the trick.
@ pWebview->setPalette(QApplication::palette("QWebView"));
page.setPalette(QApplication::palette("QWebView"));@The "older version":http://doc.qt.nokia.com/qt-maemo-4.6/maemo5-graphicswebview.html of the document was my reference when I first tried to replace QWebView with QGraphicsWebView but gave up because of the background color issue.