1

I have a QML TextArea (RichText), where I append an image from resources (using HTML ) After appending, the cursor goes automatically to 0, although I set

textArea.cursorPosition = textArea.text.length

How can I keep the cursor at the end, to keep writing?

My code:

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
        }
    }
}

Thanks, Diego

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Diego
  • 336
  • 2
  • 21
  • 1
    Possible duplicate of [QML How to put text cursor at the end of TextEdit element](https://stackoverflow.com/questions/14031070/qml-how-to-put-text-cursor-at-the-end-of-textedit-element): The trick is to use `textArea.length` instead of `textArea.text.length` – m7913d Sep 21 '17 at 12:01
  • Thanks, it works!! I didn't see the other thread, sorry – Diego Sep 21 '17 at 14:56

0 Answers0