QTextEdit *textEdit = new QTextEdit(this); QTextCursor cursor = textEdit->textCursor(); cursor.setPosition(10); // set cursor position qDebug() << "Position in block:" << cursor.positionInBlock();
QTextEdit *textEdit = new QTextEdit(this); QTextCursor cursor = textEdit->textCursor(); cursor.insertText("Hello, world!"); qDebug() << "Cursor position in block after insertion:" << cursor.positionInBlock();This example creates a QTextEdit widget, retrieves its text cursor, inserts some text, and then prints the position of the cursor in the current block after the insertion. Package library: Qt (QtCore)