QML 5.14中如何使用Markdown格式
How to use Markdown format in QML 5.14
最近 Qt 5.14 发布了。在这个版本中,他们有 added support for the Markdown format。
Added support for the Markdown format (including CommonMark and GitHub dialects) to Text and TextEdit as an alternative to HTML. This includes the GitHub checklist extension, allowing to toggle checkboxes in a TextEdit.
我希望我可以在 TextEdit or Text and my text will look like this 中输入文本。您可以在 Discord 或 Whosebug 中看到相同的结果。
但是我对此有疑问。我找不到有关如何使用它的任何文档或任何参考资料。我想,我可以在 TextEdit textFormat or Text textFormat, but there're only old html tags (they were replaced by 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
}
}
想问下有没有使用方法的文档或者例子。提前致谢!
这似乎是 Qt 文档的一个错误(QTBUG-80749), if you want to use markdown in Text
or TextEdit
那么你必须在 textFormat
属性:
中设置 TextEdit.MarkdownText
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
}
}
}
最近 Qt 5.14 发布了。在这个版本中,他们有 added support for the Markdown format。
Added support for the Markdown format (including CommonMark and GitHub dialects) to Text and TextEdit as an alternative to HTML. This includes the GitHub checklist extension, allowing to toggle checkboxes in a TextEdit.
我希望我可以在 TextEdit or Text and my text will look like this 中输入文本。您可以在 Discord 或 Whosebug 中看到相同的结果。
但是我对此有疑问。我找不到有关如何使用它的任何文档或任何参考资料。我想,我可以在 TextEdit textFormat or Text textFormat, but there're only old html tags (they were replaced by 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
}
}
想问下有没有使用方法的文档或者例子。提前致谢!
这似乎是 Qt 文档的一个错误(QTBUG-80749), if you want to use markdown in Text
or TextEdit
那么你必须在 textFormat
属性:
TextEdit.MarkdownText
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
}
}
}