View Single Post
Old 10-27-2013, 01:46 PM   #1
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,252
Karma: 16544692
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
PyQt help re: QWebView widget, please

I'm trying to experiment with the QWebView widget and having trouble getting to grips with the settings.setUserStyleSheetUrl option.

With this simple example:
Code:
self.webview = QWebView()
self.webview.setHtml(u'<body><p>This is a simple test</p></body>')
self.webview.settings().setUserStyleSheetUrl(QUrl(u'p {color:red;}'))
The html text displays OK in the widget, but the css is not used. So I'm obviously missing something basic. Please can anyone enlighten me?

Edit: Nevermind, I think I finally figured it out
This seems to work:
Code:
from base64 import b64encode
self.webview = QWebView()
self.webview.setHtml(u'<body><p>This is a simple test</p></body>')
self.webview.settings().setUserStyleSheetUrl(QUrl("data:text/css;charset=utf-8;base64," + b64encode('body {color: red}'.encode('utf-8'))))

Last edited by jackie_w; 10-27-2013 at 03:42 PM. Reason: think I've got it now
jackie_w is offline   Reply With Quote