我正在编写一个显示文件夹中静态 HTML 文件的应用程序。出于某种原因,PyQt4 的 QWebView
class 不允许渲染任何字体,即使对于远程网站:
QWebView
:
Chrome :
我正在像这样加载文件:
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/'))
是否还有其他安全设置需要更改才能使其正常工作?
最佳答案
折磨后QWebView
几个小时后,我终于注意到 Font Squirrel惊人地呈现外部字体。我多次强调这些字母,然后敬畏地坐在那里,微笑着。
无论如何,似乎是为了使这项工作与 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');
}
我不得不让它看起来像这样:
@font-face {
font-family: 'Terminal Dosis Regular';
src: url('../fonts/terminal-dosis-regular.ttf') format('truetype');
}
请注意
QWebView
不喜欢 WOFF 字体。我必须通过 Font Squirrel 将我的转换为 TrueType .简而言之:
local()
东西。 font-style
和 font-weight
被忽略。您必须为每种字体的每种样式制作不同的字体系列(例如 Terminal Dosis Bold
)。 关于qt4 - QWebView 不呈现字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11813055/