PDA

View Full Version : QML TextArea cursorPosition after adding richtext



ddonate
20th September 2017, 09:23
Hi,

I have a QML TextArea (RichText), where I append an image from resources (using HTML <img>)
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