Search code examples
qtqtextedit

QTextEdit change carriage position after setText


I can't find how to change carriage position on QTextEdit. I add text with setText(or setPlainText) methods, and after this carriage is at the beginning of QTextEdit input field, and I want it to be right after last symbol.


Solution

  • QTextCursor cursor = myQTextEdit.textCursor();
    cursor.movePosition(QTextCursor::End);
    myQTextEdit.setTextCursor(cursor);
    

    Or if it won't work, swap lines 2 and 3.