我有一个QML TextArea(RichText),我从资源中附加一个图像(使用HTML) 附加后,尽管我设置了
,但光标会自动变为0textArea.cursorPosition = textArea.text.length
如何将光标保持在最后,以便继续写作?
我的代码:
import QtQuick 2.7
import QtQuick.Controls 1.3
Item {
height: 600
width: 600
anchors.centerIn: parent
TextArea {
id: textArea
anchors.centerIn: parent
height: 300
width: 500
textFormat: TextEdit.RichText // diego.donate
verticalAlignment: TextEdit.AlignVCenter
font. pointSize: 14
horizontalAlignment: Text.AlignLeft
}
DropArea {
anchors.fill: textArea
onEntered: drag.accepted = true
onDropped: {
var sImageFromRes = "qrc:///images/image.png"
textArea.text += "<img src=" + sImageFromRes + " height=25 width=25>"
textArea.cursorPosition = textArea.text.length // NOT working
}
}
}
谢谢, 迭