简体   繁体   English

PySide-QtWebKit:CSS font-family无效

[英]PySide-QtWebKit: CSS font-family has no effect

In a QWebView, I am dynamically creating and loading HTML using QWebView.setHtml(). 在QWebView中,我使用QWebView.setHtml()动态创建和加载HTML。 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. 在我传递给这个方法的HTML字符串中,我有一个<style>部分,我从外部文件中注入一个CSS字符串。 The CSS is working beautifully, except for the font families. 除了字体系列之外,CSS工作得很漂亮。 The font always falls back to the QWebView default sans-serif font. 字体总是回退到QWebView默认的sans-serif字体。 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.settings().setFontFamily(QtWebKit.QWebSettings.StandardFont, "serif")更改默认字体,但这只会使页面上的所有内容成为serif字体,而不是遵循CSS font-family值。

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. 这不会像预期的那样以serif字体呈现,而是以通用的sans-serif字体呈现。 However, the color displays without issue. 但是,颜色显示没有问题。

At one point, to debug, I printed the complete HTML string right before calling QWebView.setHtml(), and redirected the output to a file. 有一次,为了调试,我在调用QWebView.setHtml()之前打印了完整的HTML字符串,并将输出重定向到一个文件。 This file rendered as expected when I opened it in Chromium, leading me to believe that the problem is not a HTML/CSS problem. 当我在Chromium中打开它时,此文件按预期呈现,这让我相信问题不是 HTML / CSS问题。 Here is that output if you are interested. 如果您有兴趣, 是输出。

Edit: Since I'm setting a bounty here, here is a quick tl;dr that should sum up everything important: 编辑:因为我在这里设置一个赏金,这里是一个快速tl;博士应该总结一切重要的事情:

With PySide, how can I make a QWebView honor CSS font-family settings in an HTML page that is loaded via QWebView.setHtml()? 使用PySide,如何在通过QWebView.setHtml()加载的HTML页面中创建QWebView荣誉CSS字体系列设置? 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? 或者我应该将此报告为框架中的错误?

If you want to test this out for yourself, Here is a link to the GitHub repo for the project I'm working on. 如果你想自己测试一下, 这里是我正在进行的项目的GitHub回购链接。 Dependencies are listed in the README. 依赖关系列在自述文件中。

In the header of Page.html (the one you linked) https://raw.github.com/crayZsaaron/df-legends-reader/master/page.html 在Page.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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM