[英]Why does Qt::mightBeRichText() not detact HTML table tags as rich text?
我在QML文本组件中使用HTML表。 我的问题是textFormat: Text.AutoText
无法自动将我的HTML表识别为富文本( QML Text documentary )。
在寻找解决方案时,我发现QML Text中的HTML格式非常接近我的问题。 给定的解决方案:只需设置textFormat: Text.RichText
我以前知道的textFormat: Text.RichText
。 但是我不能使用它来设置textFormat: Text.RichText
还会更改QML Text组件的contentWidth
行为。
Text {
id: myPlainText
width: 500
wrapMode: Text.Wrap
text: "Hallo stackoverflow.com"
textFormat: Text.AutoText
}
Text {
id: myRichText
width: 500
wrapMode: Text.Wrap
text: "Hallo stackoverflow.com"
textFormat: Text.RichText
}
访问myPlainText.contentWidth
将为我提供实际使用的文本,即使该文本短于500。
访问myRichText.contentWidth
确实总是给我500。
对我来说,实际使用的信息(不涉及RichText
时为contentWidth
由于布局原因很重要,因为这是我的组件最常使用的信息。 达到HTML表格的with限制(例如500)是可以的,即使这样我也希望了解实际的表格。
从文档中
如果文本格式为Text.AutoText,则文本项将自动确定是否应将文本视为样式文本 。 该确定是使用Qt :: mightBeRichText()进行的,该方法使用了快速且简单的启发式方法。 它主要检查在第一个换行符之前是否有一些看起来像标签的东西。 尽管在某些情况下结果可能是正确的,但不能保证。
如您所见,它在纯文本和样式文本之间有区别。
第三类: AutoText不支持RichText 。
这意味着对于自动图文集,您需要诉诸简化的标签集,如文档所示:
<b></b> - bold
<strong></strong> - bold
<i></i> - italic
<br> - new line
<p> - paragraph
<u> - underlined text
<font color="color_name" size="1-7"></font>
<h1> to <h6> - headers
<a href=""> - anchor
<img src="" align="top,middle,bottom" width="" height=""> - inline images
<ol type="">, <ul type=""> and <li> - ordered and unordered lists
<pre></pre> - preformatted
> < &
如果您需要文本的宽度,请尝试使用
myRichText.implicitWidth
如果没有包装,这将为您提供文本的宽度。
可能由于先进的可能性,它始终在最大contentWidth
。 因此,不可能将例如elide
与RichText
一起使用。 但是, contentWidth
的意外行为对我来说似乎是个错误-在源代码中或更可能在文档中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.