In a QWebView, I am dynamically creating and loading HTML using QWebView.setHtml(). In the HTML string that I pass to this method, I have a <style> section where I inject a CSS string from an external file. The CSS is working beautifully, except for the font families. The font always falls back to the QWebView default sans-serif font. I can change that default font using QWebView.settings().setFontFamily(QtWebKit.QWebSettings.StandardFont, "serif"), but this simply makes everything on the page a serif font instead of honoring the CSS font-family values.

在QWebView中,我使用QWebView. sethtml()动态地创建和加载HTML。在传递给这个方法的HTML字符串中,有一个

A relevant section in my CSS file:

我的CSS文件中的相关部分:

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

This does not render in a serif font as expected, but in a generic sans-serif font. However, the color displays without issue.

这并不像预期的那样以serif字体呈现,而是使用一般的sans-serif字体。然而,颜色显示没有问题。

At one point, to debug, I printed the complete HTML string right before calling QWebView.setHtml(), and redirected the output to a file. This file rendered as expected when I opened it in Chromium, leading me to believe that the problem is not a HTML/CSS problem. Here is that output if you are interested.

为了进行调试,我在调用QWebView.setHtml()之前打印了完整的HTML字符串,并将输出重定向到一个文件。当我在Chromium中打开这个文件时,这个文件被呈现出来,让我相信这个问题不是HTML/CSS的问题。如果你感兴趣的话,这是输出。

Edit: Since I'm setting a bounty here, here is a quick tl;dr that should sum up everything important:

编辑:既然我在这里设置了赏金,这里有一个快速的tl;dr应该总结所有重要的东西:

With PySide, how can I make a QWebView honor CSS font-family settings in an HTML page that is loaded via QWebView.setHtml()? Specifically, is there some secret, hidden setting that switches that kind of behavior on and off? Or should I report this as a bug in the framework?

使用PySide,如何在通过QWebView. sethtml()加载的HTML页面中创建QWebView尊重CSS字体-族设置的QWebView. sethtml ()?具体来说,是否存在某种秘密的、隐藏的设置来开关这种行为?或者我应该在框架中报告这个bug吗?

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

如果您想自己测试一下,这里有一个链接指向我正在进行的项目的GitHub repo。依赖项在README中列出。

1 个解决方案

#1


3

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

在页眉。html(你链接的那个)https://raw.github.com/crayZsaaron/df-legends-reader/master/page.html

I found this..

我发现这. .

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

Maybe try to delete this, or replace it with this

也许试着删除它,或者用这个替换它

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

更多相关文章

  1. linux修改文件所属用户和组
  2. Linux的文件权限
  3. linux系统更改目录和文件的权限总结
  4. CentOS7.2 通过nfs设置共享文件夹
  5. linux下查找包含关键字的文件
  6. Linux系统下Tar文件安装方法
  7. Linux学习笔记(九)--RedHat 7.0之用户身份与文件权限、存储结构与
  8. 在Linux用tar归档压缩文件时忽略某些文件和目录
  9. 如何查找特定用户可执行的所有文件(不是最新的)

随机推荐

  1. Android(安卓)在一个程序中启动另一个程
  2. MySQL中自增ID起始值修改方法
  3. MySQL出现SELECT list is not in GROUP B
  4. 【凯子哥带你学Android】Android专用Log
  5. 2021.1.17
  6. Debian设置允许root用户以ssh方式登录
  7. 【第562期】用 webpack 构建 node 后端代
  8. 我的51cto课程
  9. 活动|三次元世界等你来!!
  10. 自学第五十一天