[Solved] How to show image in html file with QTextBrowser?
-
wrote on 6 Aug 2011, 15:14 last edited by
Dear all,
I would like to load a html file which contains
< img src="http://www.test.com/image........>
image link.How can I show that image in QTextBrowser? It just show only unknown images...
Thanks
-
wrote on 6 Aug 2011, 23:18 last edited by
QTextBrowser only works for local files. It has no support for downloading resources from the network. If you need that, a QWebView instance would be the widget to choose.
-
wrote on 6 Aug 2011, 23:21 last edited by
Can I download the image resource to local link & use them? How can it be?
I don't want to use QWebView because it'll need QWebKit module which is heavy module.
Thanks
-
wrote on 6 Aug 2011, 23:40 last edited by
If you download the image to the local file system you would need to modify the HTML source to point to this files instead of web URLs. It's doable, but for me, this would be too awkward and error prone, I'd go with webkit.
-
wrote on 6 Aug 2011, 23:49 last edited by
I try with this implementation, but not work.
What's wrong with that..?@QVariant TextBrowser::loadResource(int type, const QUrl &name)
{
if (type == QTextDocument::ImageResource){
QFile file(srcUrl.resolved(name).toLocalFile());
if (file.open(QIODevice::ReadOnly))
return file.readAll();
}
return QTextBrowser::loadResource(type,name);
}@ -
wrote on 22 Sept 2011, 14:59 last edited by
This is my implementation for QTextDocument it should work for QTextBrowser too.
@ QVariant loadResource(int type, const QUrl &name)
{
if (type == QTextDocument::ImageResource)
{
return QImage(name.toLocalFile());
}
return QTextDocument::loadResource(type, name);
}@ -
wrote on 22 Sept 2011, 19:04 last edited by
Thanks for your reply,
When I change like that, I got error msg in console
@QColor::setNamedColor: Unknown color name 'inherit'@
Previously, I got can't get file error.Is this error due to QImage Plugins?
Thanks
-
wrote on 22 Sept 2011, 22:10 last edited by
This is strange because this function does not need anything from QColor. Missing QImage plugins are not interrupting the build process. Maybe a missing include? I have just this one: @#include <QtGui>@
Appears this message during the program run or when you try to build the binary?
-
wrote on 23 Sept 2011, 08:12 last edited by
Thanks
I already include QtGui, but not work. It appears in debug console when that function is called.
I think that might be bug. I'll make separate post for that..
-
wrote on 23 Sept 2011, 10:18 last edited by
The anser has been given in the "new thread on that error":http://developer.qt.nokia.com/forums/viewthread/9997. Please discuss the error specific topics over there.