qt - 如何在 QML 视图中修改 HTML 文本?
问题描述
是否可以在 QML 文本编辑字段中编辑(查看和保存)html 文本?或者我可以在 QML 视图中使用 TinyMCE als 编辑器吗?谢谢
解决方案
它部分工作。
我修改了示例,以便可以编辑我的 c++ 的变量。
DocumentHandler {
id: document
document: textArea.textDocument
cursorPosition: textArea.cursorPosition
selectionStart: textArea.selectionStart
selectionEnd: textArea.selectionEnd
Component.onCompleted: document.text(stringDecorator.ui_value)
onLoaded: {
textArea.text = text
}
onError: {
errorDialog.text = message
errorDialog.visible = true
}
}
Flickable {
id: flickable
flickableDirection: Flickable.VerticalFlick
anchors.fill: parent
TextArea.flickable: TextArea {
id: textArea
textFormat: Qt.RichText
wrapMode: TextArea.Wrap
focus: true
selectByMouse: true
persistentSelection: true
// Different styles have different padding and background
// decorations, but since this editor is almost taking up the
// entire window, we don't need them.
leftPadding: 6
rightPadding: 6
topPadding: 0
bottomPadding: 0
background: null
MouseArea {
acceptedButtons: Qt.RightButton
anchors.fill: parent
onClicked: contextMenu.open()
}
onLinkActivated: Qt.openUrlExternally(link)
}
ScrollBar.vertical: ScrollBar {}
}
}
Binding {
target: stringDecorator
property: "ui_value"
value: textArea.textDocument
}
如果我添加绑定以取回内容,则 textarea 将不会打印任何文本。