QTextEdit *textEdit = new QTextEdit("Hello World"); QTextCursor cursor = textEdit->textCursor(); int startPos = cursor.selectionStart(); // returns 0 since no text is selected cursor.setPosition(6); // move cursor to position 6 cursor.setPosition(9, QTextCursor::KeepAnchor); // select characters 6, 7, 8 in addition to 9 int selectionStart = cursor.selectionStart(); // returns 6
QTextEdit *textEdit = new QTextEdit("Hello World"); QTextCursor cursor = textEdit->textCursor(); cursor.setPosition(6); cursor.setPosition(9, QTextCursor::KeepAnchor); QString selectedText = cursor.selectedText(); QString replacedText = selectedText.toUpper(); cursor.insertText(replacedText);Package library: Qt C++ library.