Results 1 to 3 of 3

Thread: Saving images from QTextEdit

  1. #1
    Join Date
    Jan 2007
    Posts
    8
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Saving images from QTextEdit

    Hello all,
    I'm new to Qt and trying to build a simple text editor with support to inline images using QTextEdit.

    I am using toHtml and setHtml to load and save text content, but i also need to save images (ideally together with text, for example in a zipped file). I looked in Qt API, but it doesn't seem to be a method to access image data contained in a document.

    My idea is to save image content in a data structure (maybe a QHash) when user inserts a new image using the corresponding dialog and then using this data when saving the document. But what if an image gets inserted and then removed using backspace? Should I scan the entire document to see if some image has been removed, just before saving?
    Is there a better way of doing this?

    Thanks in advance,
    Flavio

  2. #2
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Saving images from QTextEdit

    Hello,

    I think storing your image references in a QHash might be good, but you should only store references and not the images themselves...
    Only during the saving process, you should include them in your archive.

    And if the user deletes an image, you don't have to parse all the document.
    First, you should work on the QTextDocument object, contained in QTextEdit (you can have the pointer with document()).

    Then, simply catch the contentsChange(...) signal from document, it gives you position and informations about the changes...

    Here's the doc for QTextDocument : http://doc.trolltech.com/4.1/qtextdocument.html

    Just my 2 cent...I haven't tried it myself

  3. #3
    Join Date
    Jan 2007
    Posts
    8
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Saving images from QTextEdit

    Quote Originally Posted by guilugi View Post
    Just my 2 cent...I haven't tried it myself
    Thanks, I'll try to implent it...

Similar Threads

  1. Re-implement mouse events of QTextEdit
    By Ankitha Varsha in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2006, 16:55
  2. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  3. [QT 4] QTextEdit performance
    By fellobo in forum Qt Programming
    Replies: 8
    Last Post: 6th March 2006, 19:27
  4. Painting to QTextEdit
    By gesslar in forum Qt Programming
    Replies: 8
    Last Post: 18th February 2006, 18:40
  5. Obtaining clean (x)html from QTextEdit
    By ccf_h in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2006, 14:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.