Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. MS Word like behavior with QTextEdit
Forum Updated to NodeBB v4.3 + New Features

MS Word like behavior with QTextEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 253 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bidjiz
    wrote on last edited by
    #1

    Hello,

    I want to achieve MS Word like behavior with QTextEdit - have text with images, that can be saved to a single file.
    I've seen several discussions about that, but still can`t figure out how to do this without overcompicating my solution.

    If I add image like this:

    QTextCursor cursor = textCursor();
    
    QTextImageFormat image_format;
    image_format.setName(path);
    
    cursor.beginEditBlock();
    
    cursor.insertImage(image_format);
    
    cursor.endEditBlock();
    

    I can use toHtml() to get HTML text with links to images. However, all these images are just references to some files.
    I can parse my HTML before saving and save all these files separately. But I don`t quite understand how to make QTextEdit use loaded images.

    JonBJ 1 Reply Last reply
    0
    • B bidjiz

      Hello,

      I want to achieve MS Word like behavior with QTextEdit - have text with images, that can be saved to a single file.
      I've seen several discussions about that, but still can`t figure out how to do this without overcompicating my solution.

      If I add image like this:

      QTextCursor cursor = textCursor();
      
      QTextImageFormat image_format;
      image_format.setName(path);
      
      cursor.beginEditBlock();
      
      cursor.insertImage(image_format);
      
      cursor.endEditBlock();
      

      I can use toHtml() to get HTML text with links to images. However, all these images are just references to some files.
      I can parse my HTML before saving and save all these files separately. But I don`t quite understand how to make QTextEdit use loaded images.

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @bidjiz said in MS Word like behavior with QTextEdit:

      I want to achieve MS Word like behavior with QTextEdit - have text with images, that can be saved to a single file.

      I believe this will be a vain effort, or at least pretty difficult. MS Word is a full-featured word processor, QTextEdit is not. If you look at a saved .docx file you will find it is actually a Zip file, containing other files, presumably including any images.

      So far as I know, even if a QTextImageFormat creates an embedded image in the QTextDocument (I don't know whether it does) you cannot serialize a QTextDocument yourself, and even if you use QTextDocumentWriter you can get HTML or ODF out but I don't think those embed images? Try them to see?

      B 1 Reply Last reply
      1
      • JonBJ JonB

        @bidjiz said in MS Word like behavior with QTextEdit:

        I want to achieve MS Word like behavior with QTextEdit - have text with images, that can be saved to a single file.

        I believe this will be a vain effort, or at least pretty difficult. MS Word is a full-featured word processor, QTextEdit is not. If you look at a saved .docx file you will find it is actually a Zip file, containing other files, presumably including any images.

        So far as I know, even if a QTextImageFormat creates an embedded image in the QTextDocument (I don't know whether it does) you cannot serialize a QTextDocument yourself, and even if you use QTextDocumentWriter you can get HTML or ODF out but I don't think those embed images? Try them to see?

        B Offline
        B Offline
        bidjiz
        wrote on last edited by
        #3

        @JonB Thank you for the answer. I don't want to write my own MS Word, so it's not nessesary to serialize whole QTextDocument. I would be quite happy if I will be able to pass loaded images to QTextDocument. But it seems that it needs valid images from the disk. Sure I can create them in some temporary folder, but it does not look like a good idea.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved