Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to get coordinate of the TextArea current selection text?



  • ScrollView {
        id: scroll
        width: parent.width
        height: parent.height
        contentWidth:  width
        contentHeight: col.height
        Column {
            id: col
            width: parent.width
            anchors.fill: parent
            TextArea {
                id: text
                readOnly: true
                width: parent.width
                textFormat: Text.RichText
                selectByMouse: true
            }
        }
        Component.onCompleted: {
            let i = 100;
            text.cursorPosition = i;
            text.moveCursorSelection(i+10, TextEdit.SelectCharacters);
            //How to get the Y corrdinate of the current selection text? Then I would like scroll to the corresponding position.
            let y = 0;
        }
    }
    

Log in to reply