[Qt-interest] Displaying html with images.
Constantin Makshin
dinosaur-rus at users.sourceforge.net
Wed Aug 5 14:45:02 CEST 2009
QTextEdit should be enough, just set the current directory to the
directory with your HTML file. Here is the code from my old application
(program was made for in-home use only, so "blind" assumption about
character set was OK):
QDir::setCurrent(qApp->applicationDirPath() + "/../translations");
QFile helpFile("./help-" + QSettings().value("language",
QLocale::system().name()).toString() + ".html");
if (!helpFile.open(QFile::ReadOnly))
return;
QByteArray helpText = helpFile.readAll();
helpFile.close();
// Create controls
QTextEdit* helpView = new QTextEdit(this);
// Set parameters
helpView->setReadOnly(true);
helpView->setHtml(QString::fromUtf8(helpText.constData()));
On Wed, 05 Aug 2009 05:45:08 +0400, Andrew Maclean
<andrew.amaclean at gmail.com> wrote:
> David Boosalis came up with a suggestion, involving using WebKit.
>
> Works nicely in two lines.
>
> Something like this:
>
> QUrl url(fn);
> InstructionsDlg dlg(this);
> dlg.webView->load(url);
> if ( dlg.exec() )
> {
> }
>
> Where fn is the absolute file name.
>
>
> Thanks
> Andrew
>
>
>
> On Wed, Aug 5, 2009 at 9:48 AM, Andrew
> Maclean<andrew.amaclean at gmail.com> wrote:
>> Has anyone any idea on how to display an html file that contains both
>> text and images? The images are in the same directory as the html file
>> and are relative to the file.
>>
>> I am doing something like this:
>> QString help_str;
>>
>> help_str = ifn.readAll();
>>
>> dlg.textBrowser->setHtml(help_str);
>> dlg.textBrowser->setReadOnly(true);
>>
>> But all I am not seeing the picture. I am using a textBrowser.
>>
>> Thanks
>> Andrew
>>
>>
>> --
>> ___________________________________________
>> Andrew J. P. Maclean
>> Centre for Autonomous Systems
>> The Rose Street Building J04
>> The University of Sydney 2006 NSW
>> AUSTRALIA
>> Ph: +61 2 9351 3283
>> Fax: +61 2 9351 7474
>> URL: http://www.acfr.usyd.edu.au/
>> ___________________________________________
--
Constantin "Dinosaur" Makshin
More information about the Qt-interest-old
mailing list