Bru*_*ard 4 markdown qt qml qt-quick
最近发布了Qt 5.14。在这个版本中,他们增加了对 Markdown 格式的支持。
向 Text 和 TextEdit 添加了对 Markdown 格式(包括 CommonMark 和 GitHub 方言)的支持,以替代 HTML。这包括 GitHub 清单扩展,允许在 TextEdit 中切换复选框。
我希望我可以在TextEdit或Text 中输入文本,我的文本将如下所示。您可以在 Discord 或 StackOverflow 中看到相同的结果。
但我有这个问题。我找不到有关如何使用它的任何文档或任何参考资料。我想,我可以在TextEdit textFormat或Text textFormat 中找到信息,但只有旧的 html 标签(它们被Markdown format 取代)。
这是我的代码的一部分,如果你需要的话。(代码可能会被窃听,因为更改后我还没有对其进行测试。)
import QtQuick 2.14
import QtQuick.Controls 2.14
Item {
width: 100
height: 100
Text {
id: messageText
height: 50
width: 100
text: msgLine.text
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
textFormat: Text.StyledText
font.pointSize: 13
lineHeight: 1.15
anchors.top: parent.top
}
TextEdit {
id: msgLine
height: 50
width: 100
anchors.top: messageText.bottom
Text.RichText // I have changed this value to others
verticalAlignment: Text.AlignVCenter
TextEdit.WrapAtWordBoundaryOrAnywhere
}
}
Run Code Online (Sandbox Code Playgroud)
我想问一下是否有任何关于如何使用它的文档或任何示例。提前致谢!
这似乎是Qt文档(的错误QTBUG-80749),如果你想在使用降价Text或TextEdit则必须设置TextEdit.MarkdownText在textFormat属性:
import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick.Layouts 1.14
Window {
id: root
visible: true
width: 960
height: 480
QtObject{
id: internals
property string markdown_text: "*Italic* **Bold**
# Heading 1
## Heading 2
[Link](http://a.com)
* List
* List
* List
- [x] @mentions, #refs, [links](), **formatting**, and <del>tags</del> supported
- [x] list syntax required (any unordered or ordered list supported)
- [x] this is a complete item
- [ ] this is an incomplete item
First Header | Second Header
------------ | -------------
Content from cell 1 | Content from cell 2
Content in the first column | Content in the second column
"
}
RowLayout{
anchors.fill: parent
TextEdit{
id: te_output
Layout.fillWidth: true
textFormat: TextEdit.MarkdownText
text: internals.markdown_text
}
Text{
id: t_output
Layout.fillWidth: true
textFormat: TextEdit.MarkdownText
text: internals.markdown_text
}
}
}
Run Code Online (Sandbox Code Playgroud)