QTextDocument doc("Hello world!"); QTextCursor cursor(&doc); cursor.movePosition(QTextCursor::Start); cursor.deleteChar(); // Deletes "H" QString text = doc.toPlainText(); // "ello world!"
QTextEdit edit("Hello world!"); QTextCursor cursor = edit.textCursor(); cursor.deleteChar(); // Deletes "o" QString text = edit.toPlainText(); // "Hell world!"This example demonstrates how to use the deleteChar function in a QTextEdit widget. The QTextCursor is obtained from the widget and the function is called to delete the character to the left of the cursor position. Package library: Qt library