PySide-QtWebKit: CSS font family not affected

In QWebView, I dynamically create and load HTML using QWebView.setHtml (). In the HTML line that I pass to this method, I have a <style> section where I insert the CSS line from an external file. CSS works great except for font families. The font always reverts to the default sans-serif default font QWebView. I can change this default font with QWebView.settings().setFontFamily(QtWebKit.QWebSettings.StandardFont, "serif") , but it just makes everything on the page a font in font instead of reading CSS family font values.

Corresponding section in my CSS file:

 .page-title { color:#BBBBBB; font-family:"Times New Roman",Garamond,serif; } 

This does not appear in the serif font as expected, but in the general sans-serif font. However, the color is displayed without problems.

At some point for debugging, I printed a full line of HTML right before calling QWebView.setHtml () and redirected the output to a file. This file looked as expected when I opened it in Chromium, which led me to think that the problem was not an HTML / CSS problem. Here is the conclusion if you are interested.

Edit: Since I am setting a reward here, here is a quick tl; dr, which should summarize everything important:

With PySide, how can I make CSS font settings for CSS CSS on an HTML page loaded through QWebView.setHtml ()? In particular, is there some kind of secret hidden setting that toggles this behavior on and off? Or should I report this as a framework error?

If you want to test it yourself, Here is a link to the GitHub repository for the project I'm working on. Dependencies are listed in README.

+4
source share
1 answer

In the header of the .html page (the one you linked) https://raw.github.com/crayZsaaron/df-legends-reader/master/page.html

I found this.

 .page-title { color:#BBBBBB; font-family:Helvetica, sans-serif; } 

Perhaps try removing it or replacing it with

 .page-title { color:#BBBBBB; font-family:"Times New Roman",Garamond,serif; } 
+3
source

Source: https://habr.com/ru/post/1497338/


All Articles