QTextCursor cursor = ui->textEdit->textCursor(); // Get the cursor position cursor.insertImage("image.jpg"); // Insert the image ui->textEdit->setTextCursor(cursor); // Set the new cursor position
QTextDocument *document = ui->textEdit->document(); // Get the document QTextCursor cursor = document->find("Lorem", QTextDocument::FindCaseSensitively); // Find the first occurrence of the word "Lorem" if (!cursor.isNull()) { // If the word "Lorem" is found cursor.insertImage("image.jpg"); // Insert the image ui->textEdit->setTextCursor(cursor); // Set the new cursor position }This example finds the first occurrence of the word "Lorem" in the QTextEdit widget and inserts an image named "image.jpg" at the position of the word. Package library: Qt (part of the Qt GUI module).