Results 1 to 2 of 2

Thread: Loading images in QTextBrowser

  1. #1
    Join Date
    Jan 2007
    Posts
    2
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Question Loading images in QTextBrowser

    hello all!

    I need to know how to load and insert images in QTextBrowser. Using the code below i load the image dynamically from an url eg. http://something/images/image1.gif but, stuck up with how to insert it in the QTextBroswer with the other content of the document using QTextCursor.

    QUrl url(iurl);
    QVariant cimg = teContent->loadResource(QTextDocument::ImageResource,url);
    QImage im = cimg.value<QImage>();


    I need to know how to proceed to insert the image? there is a function in QTextCursor to insertImage() which takes an object of QTextImageFormat as the argument.. How to associate the image object with the QTextImageFormat?

    Plz help.
    Nisha

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Loading images in QTextBrowser

    Quoting the docs:
    Quote Originally Posted by Rich Text Document Structure docs
    Images
    Images in QTextDocument are represented by text fragments that reference external images via the resource mechanism. Images are created using the cursor interface, and can be modified later by changing the character format of the image's text fragment:
    Qt Code:
    1. if (fragment.isValid()) {
    2. QTextImageFormat newImageFormat = fragment.charFormat().toImageFormat();
    3.  
    4. if (newImageFormat.isValid()) {
    5. newImageFormat.setName(":/images/newimage.png");
    6. QTextCursor helper = cursor;
    7.  
    8. helper.setPosition(fragment.position());
    9. helper.setPosition(fragment.position() + fragment.length(),
    10. QTextCursor::KeepAnchor);
    11. helper.setCharFormat(newImageFormat);
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    The fragment that represents the image can be found by iterating over the fragments in the text block that contains the image.

Similar Threads

  1. Replies: 1
    Last Post: 5th December 2006, 12:07
  2. JPEG Images not shown in QiconView using QT3??
    By darpan in forum Qt Programming
    Replies: 1
    Last Post: 4th August 2006, 21:34
  3. [QT4] QtextBrowser and image size (win)
    By sebgui in forum Qt Programming
    Replies: 0
    Last Post: 28th March 2006, 22:01
  4. working with images
    By Kapil in forum Newbie
    Replies: 2
    Last Post: 9th March 2006, 12:59
  5. how to adjust sizes of QTextBrowser?
    By Pan Wojtas in forum Qt Programming
    Replies: 2
    Last Post: 7th February 2006, 23:25

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.