PDA

View Full Version : Is there a widget for display HTML files?



JeffJones
23rd May 2007, 21:57
Is there a Qt widget that will allow me to populate it with HTML markup (including <img src="\dir\graphic.jpg">) for display to the user? It will need to be able to retrieve local images and provide hyperlinks. Is this possible?

thanks,
Jeff

JeffJones
23rd May 2007, 22:12
Just found the QTextBrowser widget. This seems to display HTML and images. Although I can't seem to get the path correct for displaying an image currently. But I am sure I will figure it out.

Jeff

JeffJones
24th May 2007, 15:40
Ok - how do I get a QTextBrowser to load and display a local HTML file? I seem to be having trouble understanding the C++ code required to do that. Assume the HTML file is in the program directory.

Any quick help with the C++ code required to do this would be very helpful.

Thanks,
Jeff

JeffJones
24th May 2007, 16:49
Sorry to be wasting bandwidth here. I uncovered the answer via some extended searching in these forums.



ui.textBrowser->setSource(QUrl("sample.htm"));


One problem however, I have a graphic file in the same directory as "sample.htm" - "icon5.gif". [WindowsXP, Visual Studio 2005]
The setSrouce() call finds sample.htm, however, the textBrowser loads a "missing" graphic instead of the GIF file I referenced.



<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 8.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<h1>Introduction</h1>
<p>This is the first paragraph</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<p>
<img src="icon5.gif" />
</p>
</BODY>
</HTML>


Why can't the textBrowser find and display the graphic?

Thanks,
Jeff

wysota
24th May 2007, 16:59
Maybe your Qt installation doesn't support gif images. Did you turn on GIF support for Qt? If not, then you've got your reason :)

JeffJones
24th May 2007, 17:19
It was a GIF issue. When I replaced the reference with a JPG file, it was displayed correctly.

Now, the question begs - how does one turn on GIF support?

And, if I may go ahead and piggy-back this thread with a further HTML-related question:

Can the QtextBrowser display buttons and text fields and checkboxes?

And, hoping that the answer is yes, can my code retrieve notification of button clicks; text from text fields and the status of said checkboxes?

Thanks very much for your expertise!
Jeff

Brandybuck
24th May 2007, 19:29
Now, the question begs - how does one turn on GIF support?
You need to rebuild Qt with an option to configure to compile in GIF support: -qt-gif.


Can the QtextBrowser display buttons and text fields and checkboxes?
No it can't. It's not meant to be a full HTML browser engine, just a rich text display using as subset of HTML/CSS as the markup. However, in the future we will have a pure Qt WebKit, which will be a real HTML engine. It will be several months at least though.