【问题标题】:Multiple font types in a QML TextQML 文本中的多种字体类型
【发布时间】:2018-05-26 09:34:16
【问题描述】:

我需要使用多种字体类型编写文本。我试图通过使用这样的富文本来做到这一点:

Text{
    id: test
    textFormat: Text.RichText
    color: "#297fca"
    text: "<span style = 'font-family: Roboto Medium; font-size: 15px'>Text in on font.</span> And in another"
    anchors{
        top: description.bottom
        topMargin: 40
        left: headDesign.right
        leftMargin: 75
    }
}

我要更改字体的文本变大但未加载字体。 Roboto Medium 是我使用字体加载器加载的字体。

那么,对我做错了什么有什么想法吗?

【问题讨论】:

  • 你试过FontLoader
  • 两种字体都是使用字体加载器加载的。对不起,如果我不清楚。我的意思是字体没有显示在消息中的内容中。都是默认字体
  • RichText 没有实现完整的 HTML 规范。也许 font-family 内部样式没有实现。你可以设置像Text { text: "Fixed-size font"; font.family: fixedFont.name }这样的字体,其中fixedFontFontLoader元素的id。
  • 这种方法的问题是,当你这样做时,你需要为另一种字体创建一个全新的文本字段。当您的文本是一个段落并且字体更改位于段落的中间时,这根本不是一个好的解决方案
  • 你能发布你用来加载字体的代码吗? font-family 是受支持的 CSS 属性,应该可以使用。当我尝试使用另一种字体时,你的代码对我来说效果很好,所以我相信你的加载器有问题。见Supported HTML Subset。请注意,您也可以使用font 标签:text: "&lt;font face='Roboto Medium' size='15'&gt;Text in on font.&lt;/font&gt; And in another"

标签: qt qml


【解决方案1】:

请检查字体是否正确加载。

FontLoader {
    source: "riesling.ttf"
    Component.onCompleted: console.log(name)
}

Text{
    id: test
    textFormat: Text.RichText
    color: "#297fca"
    text: "<div style = 'font-family: Riesling; font-size: 25px'>Same Text.</div>
           <div style = 'font-size: 25px'>Same Text.</div>"
}

字体:https://www.1001freefonts.com/

让它们显示单独的行以清楚地看到差异。

Qt 5.10.1 结果

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-23
    • 2012-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-25
    相关资源
    最近更新 更多