Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
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,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
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
Old 10-27-2013, 10:49 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,871
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
As you figured out, you have to use a data URL, see set_user_stylesheet() in documentview.py for an example.
kovidgoyal is offline   Reply With Quote
Advert
Old 10-28-2013, 10:00 AM   #3
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,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
Thanks for the example
jackie_w is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem loading widget oldyellr Kobo Tablets 1 08-23-2012 10:30 AM
Anyone know how to write a widget? NDRisk Kobo Tablets 9 11-27-2011 10:20 AM
Pi Chart Battery Widget aglick enTourage eDGe 2 09-18-2011 06:03 PM
PyQT warning... alexxxm Calibre 1 07-28-2008 04:18 AM
iLiad Widget style tomchek iRex Developer's Corner 5 08-02-2007 11:16 AM


All times are GMT -4. The time now is 06:34 AM.


MobileRead.com is a privately owned, operated and funded community.