QTextEdit *textEdit = new QTextEdit(); QTextCursor cursor = textEdit->textCursor(); cursor.select(QTextCursor::Document); textEdit->setTextCursor(cursor);
QString selectedText = textEdit->textCursor().selectedText();
QString newText = "Hello, world!"; QTextCursor cursor = textEdit->textCursor(); cursor.removeSelectedText(); cursor.insertText(newText);These examples demonstrate how QTextCursor selection can be used to manipulate text within a QTextEdit widget. The QTextCursor class is part of the Qt Core module, and is included in the QtWidgets package.