|  | Home · All Classes · Modules

# QWebView Class Reference
[QtWebKit module]

The QWebView class provides a widget that is used to view and edit web documents. More...

Inherits QWidget.

### Methods

- __init__ (self, QWidget parent = None)
- back (self)
- changeEvent (self, QEvent)
- contextMenuEvent (self, QContextMenuEvent)
- QWebView createWindow (self, QWebPage.WebWindowType type)
- dragEnterEvent (self, QDragEnterEvent)
- dragLeaveEvent (self, QDragLeaveEvent)
- dragMoveEvent (self, QDragMoveEvent)
- dropEvent (self, QDropEvent)
- bool event (self, QEvent)
- bool findText (self, QString subString, QWebPage.FindFlags options = 0)
- focusInEvent (self, QFocusEvent)
- bool focusNextPrevChild (self, bool next)
- focusOutEvent (self, QFocusEvent)
- forward (self)
- QWebHistory history (self)
- QIcon icon (self)
- inputMethodEvent (self, QInputMethodEvent)
- QVariant inputMethodQuery (self, Qt.InputMethodQuery property)
- bool isModified (self)
- keyPressEvent (self, QKeyEvent)
- keyReleaseEvent (self, QKeyEvent)
- load (self, QUrl url)
- load (self, QNetworkRequest request, QNetworkAccessManager.Operation operation = QNetworkAccessManager.GetOperation, QByteArray body = QByteArray())
- mouseDoubleClickEvent (self, QMouseEvent)
- mouseMoveEvent (self, QMouseEvent)
- mousePressEvent (self, QMouseEvent)
- mouseReleaseEvent (self, QMouseEvent)
- QWebPage page (self)
- QAction pageAction (self, QWebPage.WebAction action)
- paintEvent (self, QPaintEvent ev)
- print_ (self, QPrinter printer)
- reload (self)
- resizeEvent (self, QResizeEvent e)
- QString selectedText (self)
- setContent (self, QByteArray data, QString mimeType = QString(), QUrl baseUrl = QUrl())
- setHtml (self, QString html, QUrl baseUrl = QUrl())
- setPage (self, QWebPage page)
- setTextSizeMultiplier (self, float factor)
- QWebSettings settings (self)
- setUrl (self, QUrl url)
- QSize sizeHint (self)
- stop (self)
- float textSizeMultiplier (self)
- QString title (self)
- triggerPageAction (self, QWebPage.WebAction action, bool checked = False)
- QUrl url (self)
- wheelEvent (self, QWheelEvent)

### Qt Signals

- void iconChanged ()
- void linkClicked (const QUrl&)
- void loadFinished (bool)
- void loadProgress (int)
- void loadStarted ()
- void selectionChanged ()
- void statusBarMessage (const QString&)
- void titleChanged (const QString&)
- void urlChanged (const QUrl&)

## Detailed Description

The QWebView class provides a widget that is used to view and edit web documents.

QWebView is the main widget component of the QtWebKit web browsing module. It can be used in various applications to display web content live from the Internet.

The image below shows QWebView previewed in Qt Designer with the Trolltech website.

A web site can be loaded onto QWebView with the load() function. Like all Qt Widgets, the show() function must be invoked in order to display QWebView. The snippet below illustrates this:

         QWebView *view = new QWebView(parent);
         view->load(QUrl("http://www.trolltech.com/"));
         view->show();

Alternatively, setUrl() can also be used to load a web site. If you have the HTML content readily available, you can use setHtml() instead.

The loadStarted() signal is emitted when the view begins loading. The loadProgress() signal, on the other hand, is emitted whenever an element of the web view completes loading, such as an embedded image, a script, etc. Finally, the loadFinished() signal is emitted when the view has loaded completely. It's argument - either `true` or `false` - indicates load success or failure.

The page() function returns a pointer to the web page object. See Elements of QWebView for an explanation of how the web page is related to the view. To modify your web view's settings, you can access the QWebSettings object with the settings() function. With QWebSettings, you can change the default fonts, enable or disable features such as JavaScript and plugins.

The title of an HTML document can be accessed with the title() property. Additionally, a web site may also specify an icon, which can be accessed using the icon() property. If the title or the icon changes, the corresponding titleChanged() and iconChanged() signals will be emitted. The textSizeMultiplier() property can be used to change the overall size of the text displayed in the web view.

If you require a custom context menu, you can implement it by reimplementing contextMenuEvent() and populating your QMenu with the actions obtained from pageAction(). More functionality such as reloading the view, copying selected text to the clipboard, or pasting into the view, is also encapsulated within the QAction objects returned by pageAction(). These actions can be programmatically triggered using triggerPageAction(). Alternatively, the actions can be added to a toolbar or a menu directly. QWebView maintains the state of the returned actions but allows modification of action properties such as text or icon.

A QWebView can be printed onto a QPrinter using the print_() function. This function is marked as a slot and can be conveniently connected to QPrintPreviewDialog's paintRequested() signal.

If you want to provide support for web sites that allow the user to open new windows, such as pop-up windows, you can subclass QWebView and reimplement the createWindow() function.

### Elements of QWebView

QWebView consists of other objects such as QWebFrame and QWebPage. The flowchart below shows these elements are related.

Note: It is possible to use QWebPage and QWebFrame, without using QWebView, if you do not require QWidget attributes. Nevertheless, QtWebKit depends on QtGui, so you should use a QApplication instead of QCoreApplication.

See also Previewer Example and Browser.

## Method Documentation

### QWebView.__init__ (self, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs an empty QWebView with parent parent.

See also load().

### QWebView.back (self)

This method is also a Qt slot with the C++ signature `void back()`.

Convenience slot that loads the previous document in the list of documents built by navigating links. Does nothing if there is no previous document.

It is equivalent to

         view->page()->triggerAction(QWebPage.GoBack);

See also forward() and pageAction().

### QWebView.changeEvent (self, QEvent)

### QWebView.contextMenuEvent (self, QContextMenuEvent)

### QWebView QWebView.createWindow (self, QWebPage.WebWindowType type)

This function is called whenever WebKit wants to create a new window of the given type, for example as a result of a JavaScript request to open a document in a new window.

See also QWebPage.createWindow().

### QWebView.dragEnterEvent (self, QDragEnterEvent)

### QWebView.dragLeaveEvent (self, QDragLeaveEvent)

### QWebView.dragMoveEvent (self, QDragMoveEvent)

### QWebView.dropEvent (self, QDropEvent)

### bool QWebView.event (self, QEvent)

### bool QWebView.findText (self, QString subString, QWebPage.FindFlags options = 0)

Finds the next occurrence of the string, subString, in the page, using the given options. Returns true of subString was found and selects the match visually; otherwise returns false.

See also selectedText() and selectionChanged().

### QWebView.focusInEvent (self, QFocusEvent)

### bool QWebView.focusNextPrevChild (self, bool next)

### QWebView.focusOutEvent (self, QFocusEvent)

### QWebView.forward (self)

This method is also a Qt slot with the C++ signature `void forward()`.

Convenience slot that loads the next document in the list of documents built by navigating links. Does nothing if there is no next document.

It is equivalent to

         view->page()->triggerAction(QWebPage.GoForward);

See also back() and pageAction().

### QWebHistory QWebView.history (self)

Returns a pointer to the view's history of navigated web pages.

It is equivalent to

         view->page()->history();

### QIcon QWebView.icon (self)

### QWebView.inputMethodEvent (self, QInputMethodEvent)

### QVariant QWebView.inputMethodQuery (self, Qt.InputMethodQuery property)

### bool QWebView.isModified (self)

### QWebView.keyPressEvent (self, QKeyEvent)

### QWebView.keyReleaseEvent (self, QKeyEvent)

### QWebView.load (self, QUrl url)

Loads the specified url and displays it.

Note: The view remains the same until enough data has arrived to display the new url.

See also setUrl(), url(), and urlChanged().

### QWebView.load (self, QNetworkRequest request, QNetworkAccessManager.Operation operation = QNetworkAccessManager.GetOperation, QByteArray body = QByteArray())

This is an overloaded member function, provided for convenience.

Loads a network request, request, using the method specified in operation.

body is optional and is only used for POST operations.

Note: The view remains the same until enough data has arrived to display the new url.

See also url() and urlChanged().

### QWebView.mouseDoubleClickEvent (self, QMouseEvent)

### QWebView.mouseMoveEvent (self, QMouseEvent)

### QWebView.mousePressEvent (self, QMouseEvent)

### QWebView.mouseReleaseEvent (self, QMouseEvent)

### QWebPage QWebView.page (self)

Returns a pointer to the underlying web page.

See also setPage().

### QAction QWebView.pageAction (self, QWebPage.WebAction action)

Returns a pointer to a QAction that encapsulates the specified web action action.

### QWebView.paintEvent (self, QPaintEvent ev)

### QWebView.print_ (self, QPrinter printer)

This method is also a Qt slot with the C++ signature `void print(QPrinter *) const`.

Prints the main frame to the given printer.

See also QWebFrame.print() and QPrintPreviewDialog.

### QWebView.reload (self)

This method is also a Qt slot with the C++ signature `void reload()`.

Reloads the current document.

See also stop(), pageAction(), and loadStarted().

### QWebView.resizeEvent (self, QResizeEvent e)

### QString QWebView.selectedText (self)

### QWebView.setContent (self, QByteArray data, QString mimeType = QString(), QUrl baseUrl = QUrl())

Sets the content of the web view to the specified content data. If the mimeType argument is empty it is currently assumed that the content is HTML but in future versions we may introduce auto-detection.

External objects referenced in the content are located relative to baseUrl.

See also load(), setHtml(), and QWebFrame.toHtml().

### QWebView.setHtml (self, QString html, QUrl baseUrl = QUrl())

Sets the content of the web view to the specified html.

External objects referenced in the HTML document are located relative to baseUrl.

When using this method, WebKit assumes that external resources such as JavaScript programs or style sheets are encoded in UTF-8 unless otherwise specified. For example, the encoding of an external script can be specified through the charset attribute of the HTML script tag. Alternatively, the encoding can also be specified by the web server.

See also load(), setContent(), and QWebFrame.toHtml().

### QWebView.setPage (self, QWebPage page)

Makes page the new web page of the web view.

The parent QObject of the provided page remains the owner of the object. If the current document is a child of the web view, it will be deleted.

See also page().

### QWebView.setTextSizeMultiplier (self, float factor)

### QWebSettings QWebView.settings (self)

Returns a pointer to the view/page specific settings object.

It is equivalent to

         view->page()->settings();

See also QWebSettings.globalSettings().

### QWebView.setUrl (self, QUrl url)

### QSize QWebView.sizeHint (self)

### QWebView.stop (self)

This method is also a Qt slot with the C++ signature `void stop()`.

Convenience slot that stops loading the document.

It is equivalent to

         view->page()->triggerAction(QWebPage.Stop);

See also reload(), pageAction(), and loadFinished().

### float QWebView.textSizeMultiplier (self)

### QString QWebView.title (self)

### QWebView.triggerPageAction (self, QWebPage.WebAction action, bool checked = False)

Triggers the specified action. If it is a checkable action the specified checked state is assumed.

The following example triggers the copy action and therefore copies any selected text to the clipboard.

         view->triggerAction(QWebPage.Copy);

See also pageAction().

### QUrl QWebView.url (self)

### QWebView.wheelEvent (self, QWheelEvent)

## Qt Signal Documentation

### void iconChanged ()

This signal is emitted whenever the icon of the page is loaded or changes.

See also icon().

### void linkClicked (const QUrl&)

This signal is emitted whenever the user clicks on a link and the page's linkDelegationPolicy property is set to delegate the link handling for the specified url.

See also QWebPage.linkDelegationPolicy().

### void loadFinished (bool)

This signal is emitted when a load of the page is finished. ok will indicate whether the load was successful or any error occurred.

See also loadStarted().

### void loadProgress (int)

This signal is emitted every time an element in the web page completes loading and the overall loading progress advances.

This signal tracks the progress of all child frames.

The current value is provided by progress and scales from 0 to 100, which is the default range of QProgressBar.

See also loadStarted() and loadFinished().

### void loadStarted ()

This signal is emitted when a new load of the page is started.

See also loadProgress() and loadFinished().

### void selectionChanged ()

This signal is emitted whenever the selection changes.

See also selectedText().

### void statusBarMessage (const QString&)

This signal is emitted when the statusbar text is changed by the page.

### void titleChanged (const QString&)

This signal is emitted whenever the title of the main frame changes.

See also title().

### void urlChanged (const QUrl&)

This signal is emitted when the url of the view changes.

See also url() and load().