PDA

View Full Version : [QT4] QtextBrowser and image size (win)



sebgui
28th March 2006, 22:01
Hi,

I used a QTextBrowser in order to show simple http page loaded from my website. This page contains several images.

In order to get them loaded in the QTextBrowser, I subclassed it and reimplement loadResource function as this :



QVariant TextBrowserExt::loadResource ( int type, const QUrl & name )
{

if(type==QTextDocument::ImageResource ){

QHttp picturl(name.host(),80);

connect(&picturl, SIGNAL(done(bool)), this, SLOT(finClientHttp(bool)));
QHttpRequestHeader header("GET", name.path());
header.setValue("Host", name.host());
QByteArray searchstring;
QBuffer *response;
response = new QBuffer();
endRequest = false;
errorRequest = false;
timeout = false;


if (picturl.request(header, searchstring, response)) {
timer.start(10000, this);
while (!endRequest) {
QCoreApplication::processEvents();
}
timer.stop();
if (!timeout) {
if (!errorRequest) {
if (picturl.lastResponse().statusCode() == 200) {


return response->data();
}

}
}
}
}

}


This implementation is maybie not the best but it works great and I can see all the images in the QtextBrowser.

The problem is that the size of the images is not good. They all appears to be 30% more than they should do. For try, I saved the downloaded images in files and the have the good size.

I don't understand why the QTextBrowser wants to resize this pictures.

This is the content of my QtextBrowser:


<html><body><img src="http://www.mywebsite.com/myimage.jpg"></html></body>


Does somebody experience something similar to dis ?