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
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:
Code:
if (fragment.isValid()) {
if (newImageFormat.isValid()) {
newImageFormat.setName(":/images/newimage.png");
helper.setPosition(fragment.position());
helper.setPosition(fragment.position() + fragment.length(),
helper.setCharFormat(newImageFormat);
}
}
The fragment that represents the image can be found by iterating over the fragments in the text block that contains the image.