Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Start next text block below an image in a QTextDocument



  • Currently I insert a block containing a newline character to do this:
    @
    QTextDocument* myDocument = new QTextDocument(textEdit);
    textEdit->setDocument(myDocument);
    QTextCursor* myCursor = new QTextCursor(myDocument);

      // Insert an image
      QTextImageFormat imageFormat;
      imageFormat.setName("logo.jpg");
      myCursor->insertImage(imageFormat, QTextFrameFormat::InFlow);
      myCursor->insertText("\n");
      
      // Insert normal text
      myCursor->movePosition(QTextCursor::End);
      myCursor->insertText("test");
    

    @

    This seems pretty hacky. Is there a better way to make the next block of text start below the image, rather than to the right of it?


Log in to reply