简体   繁体   English

为什么Qt :: mightBeRichText()不能将HTML表格标签保留为富文本格式?

[英]Why does Qt::mightBeRichText() not detact HTML table tags as rich text?

I'm using a HTML table within a QML Text component. 我在QML文本组件中使用HTML表。 My problem is that textFormat: Text.AutoText does not automatically recognize my HTML table as a rich text ( QML Text documentary ). 我的问题是textFormat: Text.AutoText无法自动将我的HTML表识别为富文本( QML Text documentary )。

Searching for a solution I found HTML formatting in QML Text which is quite close to my problem. 在寻找解决方案时,我发现QML Text中的HTML格式非常接近我的问题。 The solution given: just setting textFormat: Text.RichText I knew before. 给定的解决方案:只需设置textFormat: Text.RichText我以前知道的textFormat: Text.RichText But I can not use it as setting the textFormat: Text.RichText also changes how the contentWidth of the QML Text component behaves. 但是我不能使用它来设置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
}

Accessing myPlainText.contentWidth will give me the actual used with of the text even if it is shorter than 500. 访问myPlainText.contentWidth将为我提供实际使用的文本,即使该文本短于500。
Accessing myRichText.contentWidth does always give me 500. 访问myRichText.contentWidth确实总是给我500。
For me the information of the actual used with, which is contentWidth when no RichText is involved, is important for layout reasons, as this is what my component is mostly used for. 对我来说,实际使用的信息(不涉及RichText时为contentWidth由于布局原因很重要,因为这是我的组件最常使用的信息。 Hitting the with limit (eg. 500) for HTML tables would be ok, even so I would prefer knowing the actual table with. 达到HTML表格的with限制(例如500)是可以的,即使这样我也希望了解实际的表格。

From the Documentation 文档中

If the text format is Text.AutoText the Text item will automatically determine whether the text should be treated as styled text . 如果文本格式为Text.AutoText,则文本项将自动确定是否应将文本视为样式文本 This determination is made using Qt::mightBeRichText() which uses a fast and therefore simple heuristic. 该确定是使用Qt :: mightBeRichText()进行的,该方法使用了快速且简单的启发式方法。 It mainly checks whether there is something that looks like a tag before the first line break. 它主要检查在第一个换行符之前是否有一些看起来像标签的东西。 Although the result may be correct for common cases, there is no guarantee. 尽管在某些情况下结果可能是正确的,但不能保证。

As you can see, it distiguishes between plain and styled text. 如您所见,它在文本和样式文本之间有区别。
The third category: RichText is not supported by AutoText . 第三类: AutoText不支持RichText

This means for AutoText you need to resort to the reduced set of tags, seen in the documentation: 这意味着对于自动图文集,您需要诉诸简化的标签集,如文档所示:

<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
&gt; &lt; &amp;

If you need the width of your text, try to use 如果您需要文本的宽度,请尝试使用

myRichText.implicitWidth

This will give you the width of the text, if it is not wrapped. 如果没有包装,这将为您提供文本的宽度。
Propbably, due to the advanced posibilities, it always works with a maximum contentWidth . 可能由于先进的可能性,它始终在最大contentWidth Therefore it is not possible to use eg elide together with RichText . 因此,不可能将例如elideRichText一起使用。 The unexpected behavior of contentWidth however seems like a bug to me - in either the source or more likely in the documentation. 但是, contentWidth的意外行为对我来说似乎是个错误-在源代码中或更可能在文档中。

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

相关问题 如何删除RTF区域字段中的HTML标签? - How to remove HTML tags in Rich Text area Fields? CKeditor 富文本编辑器在浏览器中显示 html 标签 - CKeditor rich text editor displaying html tags in browser 解析 HTML -- 为什么这个文档必须按文本而不是标签来解析? - Parsing HTML -- why does this document have to parsed by text and not by tags? Qt HTML解析没有找到任何标签 - Qt html parsing does not find any tags 为什么html标签文本是红色的? - Why is the html tags text in red? 为什么富内容中的HTML文本将图像显示为“图形”? - Why the HTML Text in Rich Content is showing image as 'Graphic'? Django:为什么我放置在 Django Summernote 中的文本在我的 Z4C4AD5FCA2E0381F74DBB1CEDAA 模板中显示 HTML 标签? - Django: Why does the text that I placed in Django Summernote displays HTML tags in my HTML template? Asp.net mvc - 如何在没有 html 标签的情况下显示富文本? - Asp.net mvc - how to show rich text without the html tags? 我如何输出个人 <p> 使用HTML Agility Pack将标签添加到富文本框中? - How do I output individual <p> tags using HTML Agility Pack to a rich text box? TinyMCE中所需的帮助,用于在不使用“ <style>” tags - Help required in TinyMCE to save HTML of the Rich Text Editor without “<style>” tags
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM