添加richtext后QML TextArea cursorPosition

时间:2017-09-20 08:13:00

标签: qt qml textarea richtext cursor-position

我有一个QML TextArea(RichText),我从资源中附加一个图像(使用HTML) 附加后,尽管我设置了

,但光标会自动变为0
textArea.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
        }
    }
}

谢谢, 迭

0 个答案:

没有答案