qt4 - QWebView 不呈现字体

标签 qt4 pyqt4 qwebview

我正在编写一个显示文件夹中静态 HTML 文件的应用程序。出于某种原因,PyQt4 的 QWebView class 不允许渲染任何字体,即使对于远程网站:

QWebView :

Bad fonts, bad

Chrome :

Good fonts

我正在像这样加载文件:

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 .

简而言之:
  • 确保您的字体是 TrueType 字体。
  • local()东西。
  • 好像font-stylefont-weight被忽略。您必须为每种字体的每种样式制作不同的字体系列(例如 Terminal Dosis Bold )。
  • 关于qt4 - QWebView 不呈现字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11813055/

    相关文章:

    qt - 如何创建多窗口 Qt 应用程序

    c++ - QGraphicsWidget 的上下文菜单事件

    c++ - 覆盖 QMessageBox::paintEvent()

    python - 如何在 pyqt 中的模型中设置组合框数据

    python - Facebook 不会在 PySide qwebview 中加载

    qt - 如何在QT5中自动隐藏QWidget?

    user-interface - 使用 pyuic4 将 UI 文件转换为 Python 问题

    python - 如何连接两个 QLineEdit 以具有相同的输入(由 QCheckBox 控制)

    html - HTML 页面不能正确显示在 QWebview 中

    multithreading - QWebView setContent 在单独的线程中