QTextEdit editor; QTextCursor cursor = editor.textCursor(); cursor.insertText("Hello World!");
QTextDocument doc; QTextCursor cursor(&doc); cursor.insertText("This text is bold.", QTextCharFormat(), QCharFormat(QFont("Arial", 14, QFont::Bold)));In this example, a new QTextDocument is created and a QTextCursor is created with the document as its parent. The cursor is then used to insert the text "This text is bold." with a bold font. The QTextCharFormat() parameter is used to apply default formatting to the text, and the QCharFormat() parameter is used to set the font to Arial with a size of 14 and a bold weight. The Qt package must be included in the project in order to use the QTextCursor class.