<字体大小= ...>标记中不Text.text

问题描述:

工作我的代码:<字体大小= ...>标记中不Text.text

import QtQuick 2.6 
import QtQuick.Window 2.2 

Window { 
    visible: true 

    Text { 
     text: ' 
      <font size="100">Large</font> 
      <font size="50">Medium</font> 
      <font size="10">Small</font> 
      ' 
    } 
} 

所有3个字显示有相同的大小。但the supported HTML subset被记录为包括<font size=...>

为什么会发生这种情况?

林不熟悉,QT间期,但也许你忘了单位“像素”和连字符“ - ”

<font-size="100px">Large</font> 

你可以达到你想要的东西,如果你使用CSS样式和属性Text.RichText

例子:

import QtQuick 2.6 
import QtQuick.Window 2.2 

Window { 
    visible: true 

    Text { 
     text: "<span style='font-size:120px;'>Large</span>"; textFormat: Text.RichText 
    } 
} 

回答更新,增加了更多的信息。

根据documentationText.StyledText是支持一些基本文本样式标记的优化格式。

的文档给你一些例子,像

<font color="color_name" size="1-7"></font> 

所以,如果你想使用<font size>,最大值为7

您可以用下面的例子测试的行为。使用尺寸大于7没有任何作用,字体保持大小7

import QtQuick 2.6 
import QtQuick.Window 2.2 

Window { 
    visible: true 

     Text { 
      y: 0 
      textFormat: Text.RichText 
      text: "<font size=1>Large</font>"; 
     } 

     Text { 
      y: 30 
      textFormat: Text.RichText 
      text: "<font size=7>Large</font>"; 
     } 

     Text { 
      y: 90 
      textFormat: Text.RichText 
      text: "<font size=10>Large</font>"; 
     } 
} 

这应该工作:

Text { 
    anchors.centerIn: parent 
    textFormat: Text.RichText 
    text: ' 
     <span style="font-size:100px;">Large</span> 
     <span style="font-size:50px;">Medium</span> 
     <span style="font-size:10px;">Small</span> 
     ' 
} 
+0

相同的答案比我。 – Tarod

+0

你好我想我们在同一时间发布。看到时间戳;) – luffy

+0

总而言之,支持似乎相当混乱,一些标签工作,其他标签不工作,其他工作有时或以意想不到的方式。 – dtech