class KHTMLPart


Table of contents
Modules
khtml Classes
All Classes
Module khtml
Namespace global
Class KHTMLPart
Inherits KParts.ReadOnlyPart

This class is khtml's main class. It features an almost complete web browser, and html renderer.

The easiest way to use this class (if you just want to display an HTML page at some URL) is the following:

KUrl url = "http://www.kde.org";
KHTMLPart *w = new KHTMLPart();
w->openUrl(url);
w->view()->resize(500, 400);
w->show();

Java and JavaScript are enabled by default depending on the user's settings. If you do not need them, and especially if you display unfiltered data from untrusted sources, it is strongly recommended to turn them off. In that case, you should also turn off the automatic redirect and plugins:

w->setJScriptEnabled(false);
w->setJavaEnabled(false);
w->setMetaRefreshEnabled(false);
w->setPluginsEnabled(false);

You may also wish to disable external references. This will prevent KHTML from loading images, frames, etc, or redirecting to external sites.

w->setOnlyLocalReferences(true);

Some apps want to write their HTML code directly into the widget instead of opening an url. You can do this in the following way:

QString myHTMLCode = ...;
KHTMLPart *w = new KHTMLPart();
w->begin();
w->write(myHTMLCode);
...
w->end();

You can do as many calls to write() as you wish. There are two write() methods, one accepting a QString and one accepting a char * argument. You should use one or the other (but not both) since the method using the char * argument does an additional decoding step to convert the written data to Unicode.

It is also possible to write content to the HTML part using the standard streaming API from KParts.ReadOnlyPart. The usage of the API is similar to that of the begin(), write(), end() process described above as the following example shows:

KHTMLPart *doc = new KHTMLPart();
doc->openStream( "text/html", KUrl() );
doc->writeStream( QCString( "

KHTML Rocks!

" ) ); doc->closeStream();

HTML Browser Widget Author Lars Knoll (knoll@kde.org)



enums

enum details

methods