KHTMLPart

KDE 4.5 PyKDE API Reference

- KDE's Python API

# KHTMLPart Class Reference

`from PyKDE4.khtml import *`

Inherits: KParts.ReadOnlyPart → KParts.Part → QObject

## Detailed Description

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( "<html><body><p>KHTML Rocks!</p></body></html>" ) );
     doc->closeStream();

HTML Browser Widget

Author:
  Lars Knoll (knoll@kde.org)

## Enumerations
CaretDisplayPolicy | { CaretVisible, CaretInvisible, CaretBlink }
DNSPrefetch | { DNSPrefetchDisabled, DNSPrefetchEnabled, DNSPrefetchOnlyWWWAndSLD }
FindOptions | { FindLinksOnly, FindNoPopups }
FormNotification | { NoNotification, Before, Only, Unused }
GUIProfile | { DefaultGUI, BrowserViewGUI }
PageSecurity | { NotCrypted, Encrypted, Mixed }
## Signals
| caretPositionChanged (DOM.Node node, long offset)
| configurationChanged ()
| docCreated ()
| formSubmitNotification (QString action, QString url, QByteArray formData, QString target, QString contentType, QString boundary)
| nodeActivated (DOM.Node a0)
| onURL (QString url)
| popupMenu (QString url, QPoint point)
| selectionChanged ()
## Methods
| __init__ (self, QWidget parentWidget=0, QObject parent=0, KHTMLPart.GUIProfile prof=KHTMLPart.DefaultGUI)
| __init__ (self, KHTMLView view, QObject parent=0, KHTMLPart.GUIProfile prof=KHTMLPart.DefaultGUI)
DOM.Node | activeNode (self)
bool | autoloadImages (self)
KUrl | backgroundURL (self)
KUrl | baseURL (self)
| begin (self, KUrl url=KUrl(), int xOffset=0, int yOffset=0)
KParts.BrowserExtension | browserExtension (self)
KParts.BrowserHostExtension | browserHostExtension (self)
KHTMLPart.CaretDisplayPolicy | caretDisplayPolicyNonFocused (self)
bool | closeUrl (self)
KUrl | completeURL (self, QString url)
KParts.ReadOnlyPart | createPart (self, QWidget parentWidget, QObject parent, QString mimetype, QString serviceName, QStringList serviceTypes, QStringList params)
KParts.ReadOnlyPart | currentFrame (self)
| customEvent (self, QEvent event)
bool | dndEnabled (self)
KHTMLPart.DNSPrefetch | dnsPrefetch (self)
bool | doCloseStream (self)
bool | doOpenStream (self, QString mimeType)
bool | doWriteStream (self, QByteArray data)
DOM.Document | document (self)
QString | documentSource (self)
QString | encoding (self)
| end (self)
QVariant | executeScript (self, DOM.Node n, QString script)
QVariant | executeScript (self, QString script)
KHTMLPart | findFrame (self, QString f)
KParts.ReadOnlyPart | findFramePart (self, QString f)
| findText (self)
| findText (self, QString str, long options, QWidget parent=0, KFindDialog findDialog=0)
| findTextBegin (self)
bool | findTextNext (self, bool reverse=0)
int | fontScaleFactor (self)
KHTMLPart.FormNotification | formNotification (self)
bool | frameExists (self, QString frameName)
QStringList | frameNames (self)
[KParts.ReadOnlyPart] | frames (self)
bool | gotoAnchor (self, QString name)
| guiActivateEvent (self, KParts.GUIActivateEvent event)
bool | hasSelection (self)
| hide (self)
DOM.HTMLDocument | htmlDocument (self)
| htmlError (self, int errorCode, QString text, KUrl reqUrl)
bool | inProgress (self)
bool | isCaretMode (self)
bool | isEditable (self)
bool | isModified (self)
bool | isPointInsideSelection (self, int x, int y)
bool | jScriptEnabled (self)
bool | javaEnabled (self)
QString | jsDefaultStatusBarText (self)
QString | jsStatusBarText (self)
QString | lastModified (self)
bool | mayPrefetchHostname (self, QString name)
bool | metaRefreshEnabled (self)
bool | nextAnchor (self)
DOM.Node | nodeUnderMouse (self)
DOM.Node | nonSharedNodeUnderMouse (self)
bool | onlyLocalReferences (self)
bool | openFile (self)
bool | openUrl (self, KUrl url)
QString | pageReferrer (self)
bool | paint (self, QPainter a0, QRect a1, int a2=0)
KHTMLPart | parentPart (self)
KParts.PartManager | partManager (self)
bool | pluginPageQuestionAsked (self, QString mimetype)
bool | pluginsEnabled (self)
| preloadScript (self, QString url, QString script)
| preloadStyleSheet (self, QString url, QString stylesheet)
bool | prevAnchor (self)
QString | referrer (self)
| restoreState (self, QDataStream stream)
bool | restored (self)
| saveState (self, QDataStream stream)
| scheduleRedirection (self, int delay, QString url, bool lockHistory=1)
| selectAll (self)
QString | selectedText (self)
QString | selectedTextAsHTML (self)
DOM.Range | selection (self)
long startOffset, long endOffset | selection (self, DOM.Node startNode, DOM.Node endNode)
| setActiveNode (self, DOM.Node node)
| setAlwaysHonourDoctype (self, bool b=1)
| setAutoloadImages (self, bool enable)
| setCaretDisplayPolicyNonFocused (self, KHTMLPart.CaretDisplayPolicy policy)
| setCaretMode (self, bool enable)
| setCaretPosition (self, DOM.Node node, long offset, bool extendSelection=0)
| setCaretVisible (self, bool show)
| setDNDEnabled (self, bool b)
| setDNSPrefetch (self, KHTMLPart.DNSPrefetch pmode)
| setEditable (self, bool enable)
bool | setEncoding (self, QString name, bool override=0)
| setFixedFont (self, QString name)
| setFontScaleFactor (self, int percent)
| setFormNotification (self, KHTMLPart.FormNotification fn)
| setJSDefaultStatusBarText (self, QString text)
| setJSStatusBarText (self, QString text)
| setJScriptEnabled (self, bool enable)
| setJavaEnabled (self, bool enable)
| setMetaRefreshEnabled (self, bool enable)
| setOnlyLocalReferences (self, bool enable)
| setPluginPageQuestionAsked (self, QString mimetype)
| setPluginsEnabled (self, bool enable)
| setSelection (self, DOM.Range a0)
| setStandardFont (self, QString name)
| setStatusBarText (self, QString a0, int a1)
| setStatusMessagesEnabled (self, bool enable)
| setSuppressedPopupIndicator (self, bool enable, KHTMLPart originPart=0)
| setURLCursor (self, QCursor c)
| setUserStyleSheet (self, KUrl url)
| setUserStyleSheet (self, QString styleSheet)
| setZoomFactor (self, int percent)
KHTMLSettings | settings (self)
| show (self)
| showError (self, KJob job)
| slotFinished (self, KJob a0)
| startingJob (self, KIO.Job a0)
bool | statusMessagesEnabled (self)
| stopAnimations (self)
| submitFormProxy (self, QString action, QString url, QByteArray formData, QString target, QString contentType=QString(), QString boundary=QString())
| timerEvent (self, QTimerEvent a0)
KUrl | toplevelURL (self)
| updateZoomFactor (self)
QCursor | urlCursor (self)
bool | urlSelected (self, QString url, int button, int state, QString _target, KParts.OpenUrlArguments args=KParts.OpenUrlArguments(), KParts.BrowserArguments browserArgs=KParts.BrowserArguments())
KHTMLView | view (self)
| write (self, QString str, int len=-1)
| write (self, QString str)
int | zoomFactor (self)

## Signal Documentation

caretPositionChanged | ( | DOM.Node | node,
|  | long | offset
| ) |  |  |

This signal is emitted whenever the caret position has been changed.

The signal transmits the position the DOM.Range way, the node and the zero-based offset within this node.

Parameters:

  | node | node which the caret is in. This can be null if the caret has been deactivated.
  | offset | offset within the node. If the node is null, the offset is meaningless.

Signal syntax:
  `QObject.connect(source, SIGNAL("caretPositionChanged(const DOM::Node&, long)"), target_slot)`

configurationChanged | ( |  | ) |

Emitted whenever the configuration has changed

Signal syntax:
  `QObject.connect(source, SIGNAL("configurationChanged()"), target_slot)`

docCreated | ( |  | ) |

Internal:

Signal syntax:
  `QObject.connect(source, SIGNAL("docCreated()"), target_slot)`

formSubmitNotification | ( | QString | action,
|  | QString | url,
|  | QByteArray | formData,
|  | QString | target,
|  | QString | contentType,
|  | QString | boundary
| ) |  |  |

If form notification is on, this will be emitted either for a form submit or before the form submit according to the setting. ### KDE4 remove me

Signal syntax:
  `QObject.connect(source, SIGNAL("formSubmitNotification(const char*, const QString&, const QByteArray&, const QString&, const QString&, const QString&)"), target_slot)`

nodeActivated | ( | DOM.Node | a0
| ) |  |  |

This signal is emitted when an element retrieves the keyboard focus. Note that the signal argument can be a null node if no element is active, meaning a node has explicitly been deactivated without a new one becoming active.

Signal syntax:
  `QObject.connect(source, SIGNAL("nodeActivated(const DOM::Node&)"), target_slot)`

onURL | ( | QString | url
| ) |  |  |

Emitted if the cursor is moved over an URL.

Signal syntax:
  `QObject.connect(source, SIGNAL("onURL(const QString&)"), target_slot)`

popupMenu | ( | QString | url,
|  | QPoint | point
| ) |  |  |

Emitted when the user clicks the right mouse button on the document. See KParts.BrowserExtension for two more popupMenu signals emitted by khtml, with much more information in the signal.

Signal syntax:
  `QObject.connect(source, SIGNAL("popupMenu(const QString&, const QPoint&)"), target_slot)`

selectionChanged | ( |  | ) |

This signal is emitted when the selection changes.

Signal syntax:
  `QObject.connect(source, SIGNAL("selectionChanged()"), target_slot)`

## Method Documentation

__init__ | ( | self, |
|  | QWidget | parentWidget=0,
|  | QObject | parent=0,
|  | KHTMLPart.GUIProfile | prof=KHTMLPart.DefaultGUI
| ) |  |  |

Constructs a new KHTMLPart.

KHTML basically consists of two objects: The KHTMLPart itself, holding the document data (DOM document), and the KHTMLView, derived from QScrollArea, in which the document content is rendered in. You can specify two different parent objects for a KHTMLPart, one parent for the KHTMLPart document and one parent for the KHTMLView. If the second parent argument is 0L, then parentWidget is used as parent for both objects, the part and the view.

__init__ | ( | self, |
|  | KHTMLView | view,
|  | QObject | parent=0,
|  | KHTMLPart.GUIProfile | prof=KHTMLPart.DefaultGUI
| ) |  |  |

Constructs a new KHTMLPart.

This constructor is useful if you wish to subclass KHTMLView. If the view passed as first argument to the constructor was built with a null KHTMLPart pointer, then the newly created KHTMLPart will be assigned as the view's part.

Therefore, you might either initialize the view as part of the initialization list of your derived KHTMLPart class constructor:

       MyKHTMLPart() : KHTMLPart( new MyKHTMLView( this ), ...

Or separately build the KHTMLView beforehand:

       KHTMLView * v = KHTMLView( 0L, parentWidget());
       KHTMLPart * p = KHTMLPart( v ); // p will be assigned to v, so that v->part() == p

DOM.Node activeNode | ( |  | self ) |

Returns the node that has the keyboard focus.

bool autoloadImages | ( |  | self ) |

Returns whether images contained in the document are loaded automatically or not.

Note:
  that the returned information is unrelieable as long as no begin() was called.

KUrl backgroundURL | ( |  | self ) |

Returns the URL for the background Image (used by save background)

KUrl baseURL | ( |  | self ) |

begin | ( | self, |
|  | KUrl | url=KUrl(),
|  | int | xOffset=0,
|  | int | yOffset=0
| ) |  |  |

Clears the widget and prepares it for new content.

If you want url() to return for example "file:/tmp/test.html", you can use the following code:

     view->begin( KUrl("file:/tmp/test.html" ) );

Parameters:

  | url | is the url of the document to be displayed. Even if you are generating the HTML on the fly, it may be useful to specify a directory so that any pixmaps are found.
  | xOffset | is the initial horizontal scrollbar value. Usually you don't want to use this.
  | yOffset | is the initial vertical scrollbar value. Usually you don't want to use this.

All child frames and the old document are removed if you call this method.

KParts.BrowserExtension browserExtension | ( |  | self ) |

Returns a pointer to the KParts.BrowserExtension.

KParts.BrowserHostExtension browserHostExtension | ( |  | self ) |

KHTMLPart.CaretDisplayPolicy caretDisplayPolicyNonFocused | ( |  | self ) |

Returns the current caret policy when the view is not focused.

bool closeUrl | ( |  | self ) |

Stops loading the document and kills all data requests (for images, etc.)

KUrl completeURL | ( | self, |
|  | QString | url
| ) |  |  |

returns a KUrl object for the given url. Use when you know what you're doing.

KParts.ReadOnlyPart createPart | ( | self, |
|  | QWidget | parentWidget,
|  | QObject | parent,
|  | QString | mimetype,
|  | QString | serviceName,
|  | QStringList | serviceTypes,
|  | QStringList | params
| ) |  |  |

This method is called when a new embedded object (include html frames) is to be created. Reimplement it if you want to add support for certain embeddable objects without registering them in the KDE wide registry system (KSyCoCa) . Another reason for re-implementing this method could be if you want to derive from KTHMLPart and also want all html frame objects to be a object of your derived type, in which case you should return a new instance for the mimetype 'text/html' .

KParts.ReadOnlyPart currentFrame | ( |  | self ) |

Return the current frame (the one that has focus) Not necessarily a direct child of ours, framesets can be nested. Returns "this" if this part isn't a frameset.

customEvent | ( | self, |
|  | QEvent | event
| ) |  |  |

bool dndEnabled | ( |  | self ) |

Returns whether Dragn'n'Drop support is enabled or not.

KHTMLPart.DNSPrefetch dnsPrefetch | ( |  | self ) |

Returns currently set DNS prefetching mode. See DNSPrefetch enum for explanation of values.

Note:
  Always returns DNSPrefetchDisabled if setOnlyLocalReferences() mode is enabled.

Since:
  4.2

bool doCloseStream | ( |  | self ) |

Implements the streaming API of KParts.ReadOnlyPart.

bool doOpenStream | ( | self, |
|  | QString | mimeType
| ) |  |  |

Implements the streaming API of KParts.ReadOnlyPart.

bool doWriteStream | ( | self, |
|  | QByteArray | data
| ) |  |  |

Implements the streaming API of KParts.ReadOnlyPart.

DOM.Document document | ( |  | self ) |

Returns a reference to the DOM document.

QString documentSource | ( |  | self ) |

Returns the content of the source document.

QString encoding | ( |  | self ) |

Returns the encoding the page currently uses.

Note that the encoding might be different from the charset.

end | ( |  | self ) |

Call this after your last call to write().

QVariant executeScript | ( | self, |
|  | DOM.Node | n,
|  | QString | script
| ) |  |  |

Execute the specified snippet of JavaScript code.

Returns true if JavaScript was enabled, no error occurred and the code returned true itself or false otherwise. @deprecated, use executeString( DOM.Node(), script)

QVariant executeScript | ( | self, |
|  | QString | script
| ) |  |  |

Execute the specified snippet of JavaScript code.

Returns true if JavaScript was enabled, no error occurred and the code returned true itself or false otherwise. @deprecated, use executeString( DOM.Node(), script)

KHTMLPart findFrame | ( | self, |
|  | QString | f
| ) |  |  |

Finds a frame by name. Returns 0L if frame can't be found.

KParts.ReadOnlyPart findFramePart | ( | self, |
|  | QString | f
| ) |  |  |

Finds a frame by name. Returns 0L if frame can't be found.

findText | ( |  | self ) |

Starts a new search, but bypasses the user dialog.

Parameters:

  | str | The string to search for.
  | options | Find options.
  | parent | Parent used for centering popups like "string not found".
  | findDialog | Optionally, you can supply your own dialog.

findText | ( | self, |
|  | QString | str,
|  | long | options,
|  | QWidget | parent=0,
|  | KFindDialog | findDialog=0
| ) |  |  |

Starts a new search, but bypasses the user dialog.

Parameters:

  | str | The string to search for.
  | options | Find options.
  | parent | Parent used for centering popups like "string not found".
  | findDialog | Optionally, you can supply your own dialog.

findTextBegin | ( |  | self ) |

Initiates a text search.

bool findTextNext | ( | self, |
|  | bool | reverse=0
| ) |  |  |

Finds the next occurrence of a string set by findText()

Parameters:

  | reverse | if true, revert seach direction (only if no find dialog is used)

Returns:
  true if a new match was found.

int fontScaleFactor | ( |  | self ) |

Returns the current font scale factor.

KHTMLPart.FormNotification formNotification | ( |  | self ) |

Determine if signal should be emitted before, instead or never when a submitForm() happens. ### KDE5 remove me

bool frameExists | ( | self, |
|  | QString | frameName
| ) |  |  |

Returns whether a frame with the specified name is exists or not. In contrast to the findFrame method this one also returns true if the frame is defined but no displaying component has been found/loaded, yet.

QStringList frameNames | ( |  | self ) |

Returns a list of names of all frame (including iframe) objects of the current document. Note that this method is not working recursively for sub-frames.

[KParts.ReadOnlyPart] frames | ( |  | self ) |

bool gotoAnchor | ( | self, |
|  | QString | name
| ) |  |  |

Finds the anchor named name.

If the anchor is found, the widget scrolls to the closest position. Returns if the anchor has been found.

guiActivateEvent | ( | self, |
|  | KParts.GUIActivateEvent | event
| ) |  |  |

Internal reimplementation of KParts.Part.guiActivateEvent .

bool hasSelection | ( |  | self ) |

Has the user selected anything?

Call selectedText() to retrieve the selected text.

Returns:
  true if there is text selected.

hide | ( |  | self ) |

Convenience method to hide the document's view.

Equivalent to widget()->hide() or view()->hide().

DOM.HTMLDocument htmlDocument | ( |  | self ) |

Returns a reference to the DOM HTML document (for non-HTML documents, returns null)

htmlError | ( | self, |
|  | int | errorCode,
|  | QString | text,
|  | KUrl | reqUrl
| ) |  |  |

presents a detailed error message to the user. errorCode kio error code, eg KIO.ERR_SERVER_TIMEOUT. text kio additional information text. url the url that triggered the error.

bool inProgress | ( |  | self ) |

Internal:

bool isCaretMode | ( |  | self ) |

Returns whether caret mode is on/off.

bool isEditable | ( |  | self ) |

Returns true if the document is editable, false otherwise.

bool isModified | ( |  | self ) |

Checks whether the page contains unsubmitted form changes.

Returns:
  true if form changes exist

bool isPointInsideSelection | ( | self, |
|  | int | x,
|  | int | y
| ) |  |  |

Returns whether the given point is inside the current selection.

The coordinates are content-coordinates.

bool jScriptEnabled | ( |  | self ) |

Returns true if Javascript support is enabled or false otherwise.

bool javaEnabled | ( |  | self ) |

Return true if Java applet support is enabled, false if disabled

QString jsDefaultStatusBarText | ( |  | self ) |

Called by KJS. Returns the DefaultStatusBarText assigned via window.defaultStatus

QString jsStatusBarText | ( |  | self ) |

Called by KJS. Returns the StatusBarText assigned via window.status

QString lastModified | ( |  | self ) |

Last-modified date (in raw string format), if received in the [HTTP] headers.

bool mayPrefetchHostname | ( | self, |
|  | QString | name
| ) |  |  |

Will pre-resolve name according to dnsPrefetch current settings Returns true if the name will be pre-resolved. Otherwise returns false.

bool metaRefreshEnabled | ( |  | self ) |

Returns true if automatic forwarding is enabled.

bool nextAnchor | ( |  | self ) |

Go to the next anchor

This is useful to navigate from outside the navigator

DOM.Node nodeUnderMouse | ( |  | self ) |

Returns the Node currently under the mouse.

The returned node may be a shared node (e. g. an <area> node if the mouse is hovering over an image map).

DOM.Node nonSharedNodeUnderMouse | ( |  | self ) |

Returns the Node currently under the mouse that is not shared.

The returned node is always the node that is physically under the mouse pointer (irrespective of logically overlying elements like, e. g., <area> on image maps).

bool onlyLocalReferences | ( |  | self ) |

Returns whether only file:/ or data:/ references are allowed to be loaded ( default false ). See setOnlyLocalReferences.

bool openFile | ( |  | self ) |

Internal empty reimplementation of KParts.ReadOnlyPart.openFile .

bool openUrl | ( | self, |
|  | KUrl | url
| ) |  |  |

Opens the specified URL url.

Reimplemented from KParts.ReadOnlyPart.openUrl .

QString pageReferrer | ( |  | self ) |

Referrer used to obtain this page.

bool paint | ( | self, |
|  | QPainter | a0,
|  | QRect | a1,
|  | int | a2=0
| ) |  |  |

Paints the HTML page to a QPainter. See KHTMLView.paint for details

KHTMLPart parentPart | ( |  | self ) |

Returns a pointer to the parent KHTMLPart if the part is a frame in an HTML frameset.

Returns 0L otherwise.

KParts.PartManager partManager | ( |  | self ) |

Returns a reference to the partmanager instance which manages html frame objects.

bool pluginPageQuestionAsked | ( | self, |
|  | QString | mimetype
| ) |  |  |

bool pluginsEnabled | ( |  | self ) |

Returns true if plugins are enabled, false if disabled.

preloadScript | ( | self, |
|  | QString | url,
|  | QString | script
| ) |  |  |

Loads a script into the script cache.

preloadStyleSheet | ( | self, |
|  | QString | url,
|  | QString | stylesheet
| ) |  |  |

Loads a style sheet into the stylesheet cache.

bool prevAnchor | ( |  | self ) |

Go to previous anchor

QString referrer | ( |  | self ) |

Referrer used for links in this page.

restoreState | ( | self, |
|  | QDataStream | stream
| ) |  |  |

Restores the KHTMLPart's previously saved state (including child frame objects) from the provided QDataStream.

See also:
  saveState()

This is called from the restoreState() method of the browserExtension() .

bool restored | ( |  | self ) |

Internal:

saveState | ( | self, |
|  | QDataStream | stream
| ) |  |  |

Saves the KHTMLPart's complete state (including child frame objects) to the provided QDataStream.

This is called from the saveState() method of the browserExtension().

scheduleRedirection | ( | self, |
|  | int | delay,
|  | QString | url,
|  | bool | lockHistory=1
| ) |  |  |

Schedules a redirection after delay seconds.

selectAll | ( |  | self ) |

Marks all text in the document as selected.

QString selectedText | ( |  | self ) |

Returns the text the user has marked.

QString selectedTextAsHTML | ( |  | self ) |

Return the text the user has marked. This is guaranteed to be valid xml, and to contain the <html> and <body> tags.

FIXME probably should make virtual for 4.0 ?

DOM.Range selection | ( |  | self ) |

Returns the selected part of the HTML by returning the starting and end position.

If there is no selection, both nodes and offsets are equal.

Parameters:

  | startNode | returns node selection starts in
  | startOffset | returns offset within starting node
  | endNode | returns node selection ends in
  | endOffset | returns offset within end node.

long startOffset, long endOffset selection | ( | self, |
|  | DOM.Node | startNode,
|  | DOM.Node | endNode
| ) |  |  |

Returns the selected part of the HTML by returning the starting and end position.

If there is no selection, both nodes and offsets are equal.

Parameters:

  | startNode | returns node selection starts in
  | startOffset | returns offset within starting node
  | endNode | returns node selection ends in
  | endOffset | returns offset within end node.

setActiveNode | ( | self, |
|  | DOM.Node | node
| ) |  |  |

Sets the focused node of the document to the specified node. If the node is a form control, the control will receive focus in the same way that it would if the user had clicked on it or tabbed to it with the keyboard. For most other types of elements, there is no visual indication of whether or not they are focused.

See activeNode

Parameters:

  | node | The node to focus

setAlwaysHonourDoctype | ( | self, |
|  | bool | b=1
| ) |  |  |

Sets whether the document's Doctype should always be used to determine the parsing mode for the document.

Without this, parsing will be forced to strict mode when using the write( const QString &str ) method for backward compatibility reasons.

setAutoloadImages | ( | self, |
|  | bool | enable
| ) |  |  |

Specifies whether images contained in the document should be loaded automatically or not.

Note:
  Request will be ignored if called before begin().

setCaretDisplayPolicyNonFocused | ( | self, |
|  | KHTMLPart.CaretDisplayPolicy | policy
| ) |  |  |

Sets the caret display policy when the view is not focused.

Whenever the caret is in use, this property determines how the caret should be displayed when the document view is not focused.

The default policy is CaretInvisible.

Parameters:

  | policy | new display policy

setCaretMode | ( | self, |
|  | bool | enable
| ) |  |  |

Enables/disables caret mode.

Enabling caret mode displays a caret which can be used to navigate the document using the keyboard only. Caret mode is switched off by default.

Parameters:

  | enable | true to enable, false to disable caret mode.

setCaretPosition | ( | self, |
|  | DOM.Node | node,
|  | long | offset,
|  | bool | extendSelection=0
| ) |  |  |

Sets the caret to the given position.

If the given location is invalid, it will snap to the nearest valid location. Immediately afterwards a caretPositionChanged signal containing the effective position is emitted

Parameters:

  | node | node to set to
  | offset | zero-based offset within the node
  | extendSelection | If true, a selection will be spanned from the last caret position to the given one. Otherwise, any existing selection will be deselected.

setCaretVisible | ( | self, |
|  | bool | show
| ) |  |  |

Sets the visibility of the caret.

This methods displays or hides the caret regardless of the current caret display policy (see setCaretDisplayNonFocused), and regardless of focus.

The caret will be shown/hidden only under at least one of the following conditions:

- the document is editable
- the document is in caret mode
- the document's currently focused element is editable

Parameters:

  | show | true to make visible, false to hide.

setDNDEnabled | ( | self, |
|  | bool | b
| ) |  |  |

Enables or disables Drag'n'Drop support. A drag operation is started if the users drags a link.

setDNSPrefetch | ( | self, |
|  | KHTMLPart.DNSPrefetch | pmode
| ) |  |  |

Sets whether DNS Names found in loaded documents'anchors should be pre-fetched (pre-resolved). Note that calling this function will permanently override the User settings about DNS prefetch support. Not calling this function is the only way to let the default settings apply.

Note:
  This setting has no effect if setOnlyLocalReferences() mode is enabled.

Parameters:

  | pmode | the mode to set. See DNSPrefetch enum for explanation of values.

Since:
  4.2

setEditable | ( | self, |
|  | bool | enable
| ) |  |  |

Makes the document editable.

Setting this property to true makes the document, and its subdocuments (such as frames, iframes, objects) editable as a whole. FIXME: insert more information about navigation, features etc. as seen fit

Parameters:

  | enable | true to set document editable, false to set it read-only.

bool setEncoding | ( | self, |
|  | QString | name,
|  | bool | override=0
| ) |  |  |

Sets the encoding the page uses.

This can be different from the charset. The widget will try to reload the current page in the new encoding, if url() is not empty.

setFixedFont | ( | self, |
|  | QString | name
| ) |  |  |

Sets the fixed font style.

Parameters:

  | name | The font name to use for fixed text, e.g. the <tt>&lt;pre&gt;</tt> tag.

setFontScaleFactor | ( | self, |
|  | int | percent
| ) |  |  |

Sets the scale factor to be applied to fonts. The value is given in percent, larger values mean generally larger fonts.

The given value should be in the range of 20..300, values outside that range are not guaranteed to work. A value of 100 will disable all scaling of font sizes and show the page with the sizes determined via the given lengths in the stylesheets.

setFormNotification | ( | self, |
|  | KHTMLPart.FormNotification | fn
| ) |  |  |

Determine if signal should be emitted before, instead or never when a submitForm() happens. ### KDE5 remove me

setJSDefaultStatusBarText | ( | self, |
|  | QString | text
| ) |  |  |

Called by KJS. Sets the DefaultStatusBarText assigned via window.defaultStatus

setJSStatusBarText | ( | self, |
|  | QString | text
| ) |  |  |

Called by KJS. Sets the StatusBarText assigned via window.status

setJScriptEnabled | ( | self, |
|  | bool | enable
| ) |  |  |

Enable/disable Javascript support. Note that this will in either case permanently override the default usersetting. If you want to have the default UserSettings, don't call this method.

setJavaEnabled | ( | self, |
|  | bool | enable
| ) |  |  |

Enables/disables Java applet support. Note that calling this function will permanently override the User settings about Java applet support. Not calling this function is the only way to let the default settings apply.

setMetaRefreshEnabled | ( | self, |
|  | bool | enable
| ) |  |  |

Enable/disable automatic forwarding by &lt;meta http-equiv="refresh" ....&gt;

setOnlyLocalReferences | ( | self, |
|  | bool | enable
| ) |  |  |

Security option.

Specify whether only file:/ or data:/ urls are allowed to be loaded without user confirmation by KHTML. ( for example referenced by stylesheets, images, scripts, subdocuments, embedded elements ).

This option is mainly intended for enabling the "mail reader mode", where you load untrusted content with a file:/ url.

Please note that enabling this option currently automatically disables Javascript, Java and Plugins support. This might change in the future if the security model is becoming more sophisticated, so don't rely on this behaviour.

( default false - everything is loaded unless forbidden by KApplication.authorizeURLAction).

setPluginPageQuestionAsked | ( | self, |
|  | QString | mimetype
| ) |  |  |

setPluginsEnabled | ( | self, |
|  | bool | enable
| ) |  |  |

Enables or disables plugins, default is enabled

setSelection | ( | self, |
|  | DOM.Range | a0
| ) |  |  |

Sets the current selection.

setStandardFont | ( | self, |
|  | QString | name
| ) |  |  |

Sets the standard font style.

Parameters:

  | name | The font name to use for standard text.

setStatusBarText | ( | self, |
|  | QString | a0,
|  | int | a1
| ) |  |  |

setStatusMessagesEnabled | ( | self, |
|  | bool | enable
| ) |  |  |

Enable/disable statusbar messages. When this class wants to set the statusbar text, it emits setStatusBarText(const QString & text) If you want to catch this for your own statusbar, note that it returns back a rich text string, starting with "<qt>". This you need to either pass this into your own QLabel or to strip out the tags before passing it to QStatusBar.message(const QString & message)

See also:
  KParts.Part.setStatusBarText( const QString & text )

setSuppressedPopupIndicator | ( | self, |
|  | bool | enable,
|  | KHTMLPart | originPart=0
| ) |  |  |

Shows or hides the suppressed popup indicator

setURLCursor | ( | self, |
|  | QCursor | c
| ) |  |  |

Sets the cursor to use when the cursor is on a link.

setUserStyleSheet | ( | self, |
|  | KUrl | url
| ) |  |  |

Sets a user defined style sheet to be used on top of the HTML 4 default style sheet.

This gives a wide range of possibilities to change the layout of the page.

To have an effect this function has to be called after calling begin().

setUserStyleSheet | ( | self, |
|  | QString | styleSheet
| ) |  |  |

Sets a user defined style sheet to be used on top of the HTML 4 default style sheet.

This gives a wide range of possibilities to change the layout of the page.

To have an effect this function has to be called after calling begin().

setZoomFactor | ( | self, |
|  | int | percent
| ) |  |  |

Sets the Zoom factor. The value is given in percent, larger values mean a generally larger font and larger page contents.

The given value should be in the range of 20..300, values outside that range are not guaranteed to work. A value of 100 will disable all zooming and show the page with the sizes determined via the given lengths in the stylesheets.

KHTMLSettings settings | ( |  | self ) |

Internal:

show | ( |  | self ) |

Convenience method to show the document's view.

Equivalent to widget()->show() or view()->show() .

showError | ( | self, |
|  | KJob | job
| ) |  |  |

Called when a certain error situation (i.e. connection timed out) occurred. The default implementation either shows a KIO error dialog or loads a more verbose error description a as page, depending on the users configuration. job is the job that signaled the error situation

slotFinished | ( | self, |
|  | KJob | a0
| ) |  |  |

Called when the job downloading the page is finished. Can be reimplemented, for instance to get metadata out of the job, but make sure to call KHTMLPart.slotFinished() too.

startingJob | ( | self, |
|  | KIO.Job | a0
| ) |  |  |

Hook for adding code before a job is started. This can be used to add metadata, like job->addMetaData("PropagateHttpHeader", "true") to get the HTTP headers.

bool statusMessagesEnabled | ( |  | self ) |

Returns true if status messages are enabled.

stopAnimations | ( |  | self ) |

Stops all animated images on the current and child pages

submitFormProxy | ( | self, |
|  | QString | action,
|  | QString | url,
|  | QByteArray | formData,
|  | QString | target,
|  | QString | contentType=QString(),
|  | QString | boundary=QString()
| ) |  |  |

timerEvent | ( | self, |
|  | QTimerEvent | a0
| ) |  |  |

Internal:

KUrl toplevelURL | ( |  | self ) |

Returns the toplevel (origin) URL of this document, even if this part is a frame or an iframe.

Returns:
  the actual original url.

updateZoomFactor | ( |  | self ) |

Internal:

QCursor urlCursor | ( |  | self ) |

Returns the cursor which is used when the cursor is on a link.

bool urlSelected | ( | self, |
|  | QString | url,
|  | int | button,
|  | int | state,
|  | QString | _target,
|  | KParts.OpenUrlArguments | args=KParts.OpenUrlArguments(),
|  | KParts.BrowserArguments | browserArgs=KParts.BrowserArguments()
| ) |  |  |

KHTMLView view | ( |  | self ) |

Returns a pointer to the HTML document's view.

write | ( | self, |
|  | QString | str,
|  | int | len=-1
| ) |  |  |

Writes another part of the HTML code to the widget.

You may call this function many times in sequence. But remember: The fewer calls you make, the faster the widget will be.

For historic and backward compatibility reasons, this method will force the use of strict mode for the document, unless setAlwaysHonourDoctype() has been called previously.

write | ( | self, |
|  | QString | str
| ) |  |  |

Writes another part of the HTML code to the widget.

You may call this function many times in sequence. But remember: The fewer calls you make, the faster the widget will be.

For historic and backward compatibility reasons, this method will force the use of strict mode for the document, unless setAlwaysHonourDoctype() has been called previously.

int zoomFactor | ( |  | self ) |

Returns the current zoom factor.

## Enumeration Documentation

CaretDisplayPolicy

Enumeration for displaying the caret.

Enumerator:

  CaretVisible |
  CaretInvisible |
  CaretBlink |

DNSPrefetch

DNS Prefetching Mode enumeration

- DNSPrefetchDisabled do not prefetch hostnames
- DNSPrefetchEnabled always prefetch hostnames
- DNSPrefetchOnlyWWWAndSLD only do DNS prefetching for bare SLD and www sub-domain

Enumerator:

  DNSPrefetchDisabled = 0 |
  DNSPrefetchEnabled |
  DNSPrefetchOnlyWWWAndSLD |

FindOptions

Extra Find options that can be used when calling the extended findText().

Enumerator:

  FindLinksOnly = 1*KFind::MinimumUserOption |
  FindNoPopups = 2*KFind::MinimumUserOption |

FormNotification

Enumerator:

  NoNotification = 0 |
  Before |
  Only |
  Unused = 255 |

GUIProfile

Enumerator:

  DefaultGUI |
  BrowserViewGUI |

PageSecurity

Enumerator:

  NotCrypted |
  Encrypted |
  Mixed |