QWebView does not display fonts

I am writing an application that displays static HTML files from a folder. For some reason, the PyQt4 QWebView class QWebView not allow fonts to be displayed even for remote websites:

QWebView

Bad fonts, bad

Chrome

Good fonts

I upload the file as follows:

 self.web_view = QWebView() self.settings = self.web_view.settings() self.settings.setAttribute(QWebSettings.LocalContentCanAccessRemoteUrls, True) self.web_view.load(QUrl('http://blender3d.github.com/Bevel/demo/')) 

Are there any other security settings that I have to change to make this work?

+4
source share
3 answers

After QWebView for hours and hours, I finally noticed that Font Squirrel amazingly rendered the external font. I highlighted letters many times and sat there in fear, smiling.

In any case, it seems to make this work with QWebView :

 @font-face { font-family: 'Terminal Dosis'; font-style: normal; font-weight: 400; src: local('Dosis Regular'), local('Dosis-Regular'), url('../fonts/terminal-dosis-regular.woff') format('woff'); } 

I had to do it like this:

 @font-face { font-family: 'Terminal Dosis Regular'; src: url('../fonts/terminal-dosis-regular.ttf') format('truetype'); } 

Please note that QWebView does not like WOFF fonts. I had to convert my version to TrueType through Font Squirrel .

In short:

  • Make sure your fonts are TrueType fonts.
  • No local() .
  • It looks like font-style and font-weight ignored. You must create different font families for each style of each font (for example, Terminal Dosis Bold ).
+6
source

the url example stylesheet uses the css @font-face rule to specify online fonts.

Unfortunately, it looks like this is currently broken in QWebKit: Error 36351 .

0
source
0
source

All Articles