【问题标题】:QML Text with <hr> Line带有 <hr> 行的 QML 文本
【发布时间】:2021-05-18 07:13:38
【问题描述】:

我正在尝试在 QML 中显示一条水平线,并支持 HTML 4 子集。 不幸的是,我无法显示该行。例如下面的代码,不显示水平线。 我尝试了不同版本的 hr-tag:&lt;hr&gt;&lt;hr/&gt;&lt;hr&gt;&lt;/hr&gt;。但到目前为止,它们都没有工作。

import QtQuick 2.12
import QtQuick.Window 2.12

Window {
    id: root

    width: 640
    height: 480
    visible: true

    Text {
        anchors.fill: parent
        textFormat: Text.RichText
        text: "Hello<hr>Hello"
    }
}

任何想法如何解决这个问题?

【问题讨论】:

标签: html qt qml qt5


【解决方案1】:

这是一个已知的错误:

https://bugreports.qt.io/browse/QTBUG-74342

您可以像这样拆分富文本块:

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Layouts 1.12

Window {
    id: root

    width: 640
    height: 480
    visible: true

    ColumnLayout {
        Text {
            textFormat: Text.RichText
            text: "Hello"
        }

        Rectangle {
            Layout.fillWidth: true
            Layout.preferredHeight: 1
            color: "black"
        }
        Text {
            textFormat: Text.RichText
            text: "Hello"
        }
    }
}

【讨论】:

  • 感谢您的回答。我很害怕,这就是答案:/。我收到的 HTML 字符串是可变的。因此,我必须将它分成几个字符串/行并使用 ListModel + DelegateChooser。开销太大。但我很感谢你的回答!
猜你喜欢
  • 2014-06-16
  • 2018-07-25
  • 2012-05-26
  • 2016-06-18
  • 1970-01-01
  • 1970-01-01
  • 2019-04-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多