Move TextArea cursor on MouseArea click in QML

1.6k views Asked by At

There is a TextArea and i have set activeFocusOnPress porperty to false to block Virtual keyboard pop up, But when user clicks on the TextArea the cursor position should move. To achive this i thought mousearea will be good option. Following is the code:

TextArea{
    id:textArea
    text:"ABCDEFGHIJKLMNOPQRSTUVWXYZ"    
    width:100
    height: 200
    color: "white"
    cursorVisible: true
    activeFocusOnPress: false //To Block virtual Keyboard popup

    background: Rectangle{
        color:"transparent"
        border.color : "white"
        border.width:2
        MouseArea{
            id:mousearea
            anchors.fill:parent
            onClicked: {

                //*** How to set cursor position??                    
            }
        }
    }
}
1

There are 1 answers

0
dtech On BEST ANSWER

How about this?

textArea.cursorPosition = textArea.positionAt(mouseX, mouseY)