QWebView

Synopsis

Functions

Virtual functions

Slots

Signals

Detailed Description

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

PySide.QtWebKit.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.

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

view = QWebView(parent)
view.load(QUrl("http://qt.nokia.com/"))
view.show()

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

The PySide.QtWebKit.QWebView.loadStarted() signal is emitted when the view begins loading. The PySide.QtWebKit.QWebView.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 PySide.QtWebKit.QWebView.loadFinished() signal is emitted when the view has loaded completely. It’s argument - either true or false - indicates load success or failure.

The PySide.QtWebKit.QWebView.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 PySide.QtWebKit.QWebSettings object with the PySide.QtWebKit.QWebView.settings() function. With PySide.QtWebKit.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 PySide.QtWebKit.QWebView.title() property. Additionally, a web site may also specify an icon, which can be accessed using the PySide.QtWebKit.QWebView.icon() property. If the title or the icon changes, the corresponding PySide.QtWebKit.QWebView.titleChanged() and PySide.QtWebKit.QWebView.iconChanged() signals will be emitted. The PySide.QtWebKit.QWebView.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 PySide.QtGui.QWidget.contextMenuEvent() and populating your PySide.QtGui.QMenu with the actions obtained from PySide.QtWebKit.QWebView.pageAction() . More functionality such as reloading the view, copying selected text to the clipboard, or pasting into the view, is also encapsulated within the PySide.QtGui.QAction objects returned by PySide.QtWebKit.QWebView.pageAction() . These actions can be programmatically triggered using PySide.QtWebKit.QWebView.triggerPageAction() . Alternatively, the actions can be added to a toolbar or a menu directly. PySide.QtWebKit.QWebView maintains the state of the returned actions but allows modification of action properties such as PySide.QtGui.QAction.text() or PySide.QtGui.QAction.icon() .

A PySide.QtWebKit.QWebView can be printed onto a PySide.QtGui.QPrinter using the print() function. This function is marked as a slot and can be conveniently connected to PySide.QtGui.QPrintPreviewDialog ‘s PySide.QtGui.QPrintPreviewDialog.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 PySide.QtWebKit.QWebView and reimplement the PySide.QtWebKit.QWebView.createWindow() function.

Elements of QWebView

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

../../_images/qwebview-diagram.png

Note

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

See also

Previewer Example Web Browser Form Extractor Example Google Chat Example Fancy Browser Example

class PySide.QtWebKit.QWebView([parent=None])
Parameters:parentPySide.QtGui.QWidget

Constructs an empty PySide.QtWebKit.QWebView with parent parent .

PySide.QtWebKit.QWebView.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().triggerPageAction(QWebPage.GoBack)
PySide.QtWebKit.QWebView.createWindow(type)
Parameters:typePySide.QtWebKit.QWebPage.WebWindowType
Return type:PySide.QtWebKit.QWebView
PySide.QtWebKit.QWebView.findText(subString[, options=0])
Parameters:
  • subString – unicode
  • optionsPySide.QtWebKit.QWebPage.FindFlags
Return type:

PySide.QtCore.bool

PySide.QtWebKit.QWebView.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().triggerPageAction(QWebPage.GoForward)
PySide.QtWebKit.QWebView.hasSelection()
Return type:PySide.QtCore.bool

This property holds whether this page contains selected content or not..

By default, this property is false.

PySide.QtWebKit.QWebView.history()
Return type:PySide.QtWebKit.QWebHistory

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

It is equivalent to

view.page().history()
PySide.QtWebKit.QWebView.icon()
Return type:PySide.QtGui.QIcon

This property holds the icon associated with the web page currently viewed.

By default, this property contains a null icon.

PySide.QtWebKit.QWebView.iconChanged()
PySide.QtWebKit.QWebView.isModified()
Return type:PySide.QtCore.bool

This property holds whether the document was modified by the user.

Parts of HTML documents can be editable for example through the contenteditable attribute on HTML elements.

By default, this property is false.

PySide.QtWebKit.QWebView.linkClicked(arg__1)
Parameters:arg__1PySide.QtCore.QUrl
PySide.QtWebKit.QWebView.load(url)
Parameters:urlPySide.QtCore.QUrl

Loads the specified url and displays it.

Note

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

PySide.QtWebKit.QWebView.load(request[, operation=QNetworkAccessManager.GetOperation[, body=QByteArray()]])
Parameters:
PySide.QtWebKit.QWebView.loadFinished(arg__1)
Parameters:arg__1PySide.QtCore.bool
PySide.QtWebKit.QWebView.loadProgress(progress)
Parameters:progressPySide.QtCore.int
PySide.QtWebKit.QWebView.loadStarted()
PySide.QtWebKit.QWebView.page()
Return type:PySide.QtWebKit.QWebPage

Returns a pointer to the underlying web page.

PySide.QtWebKit.QWebView.pageAction(action)
Parameters:actionPySide.QtWebKit.QWebPage.WebAction
Return type:PySide.QtGui.QAction
PySide.QtWebKit.QWebView.print_(arg__1)
Parameters:arg__1PySide.QtGui.QPrinter

Prints the main frame to the given printer .

See also

QWebFrame.print() PySide.QtGui.QPrintPreviewDialog

PySide.QtWebKit.QWebView.reload()

Reloads the current document.

PySide.QtWebKit.QWebView.renderHints()
Return type:PySide.QtGui.QPainter.RenderHints

This property holds the default render hints for the view.

These hints are used to initialize PySide.QtGui.QPainter before painting the Web page.

QPainter.TextAntialiasing and QPainter.SmoothPixmapTransform are enabled by default.

Note

This property is not available on Symbian. However, the getter and setter functions can still be used directly.

See also

QPainter.renderHints()

PySide.QtWebKit.QWebView.selectedHtml()
Return type:unicode

This property holds the HTML currently selected.

By default, this property contains an empty string.

PySide.QtWebKit.QWebView.selectedText()
Return type:unicode

This property holds the text currently selected.

By default, this property contains an empty string.

PySide.QtWebKit.QWebView.selectionChanged()
PySide.QtWebKit.QWebView.setContent(data[, mimeType=""[, baseUrl=QUrl()]])
Parameters:

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 .

The data is loaded immediately; external objects are loaded asynchronously.

PySide.QtWebKit.QWebView.setHtml(html[, baseUrl=QUrl()])
Parameters:

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

External objects such as stylesheets or images referenced in the HTML document are located relative to baseUrl .

The html is loaded immediately; external objects are loaded asynchronously.

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.

This is a convenience function equivalent to setContent(html, “text/html”, baseUrl).

Warning

This function works only for HTML, for other mime types (i.e. XHTML, SVG) PySide.QtWebKit.QWebView.setContent() should be used instead.

PySide.QtWebKit.QWebView.setPage(page)
Parameters:pagePySide.QtWebKit.QWebPage

Makes page the new web page of the web view.

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

PySide.QtWebKit.QWebView.setRenderHint(hint[, enabled=true])
Parameters:
  • hintPySide.QtGui.QPainter.RenderHint
  • enabledPySide.QtCore.bool
PySide.QtWebKit.QWebView.setRenderHints(hints)
Parameters:hintsPySide.QtGui.QPainter.RenderHints

This property holds the default render hints for the view.

These hints are used to initialize PySide.QtGui.QPainter before painting the Web page.

QPainter.TextAntialiasing and QPainter.SmoothPixmapTransform are enabled by default.

Note

This property is not available on Symbian. However, the getter and setter functions can still be used directly.

See also

QPainter.renderHints()

PySide.QtWebKit.QWebView.setTextSizeMultiplier(factor)
Parameters:factorPySide.QtCore.qreal

This property holds the scaling factor for all text in the frame.

Use setZoomFactor instead, in combination with the ZoomTextOnly attribute in PySide.QtWebKit.QWebSettings .

Note

Setting this property also enables the ZoomTextOnly attribute in PySide.QtWebKit.QWebSettings .

By default, this property contains a value of 1.0.

PySide.QtWebKit.QWebView.setUrl(url)
Parameters:urlPySide.QtCore.QUrl

This property holds the url of the web page currently viewed.

Setting this property clears the view and loads the URL.

By default, this property contains an empty, invalid URL.

PySide.QtWebKit.QWebView.setZoomFactor(factor)
Parameters:factorPySide.QtCore.qreal

This property holds the zoom factor for the view.

PySide.QtWebKit.QWebView.settings()
Return type:PySide.QtWebKit.QWebSettings

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

It is equivalent to

view.page().settings()
PySide.QtWebKit.QWebView.statusBarMessage(text)
Parameters:text – unicode
PySide.QtWebKit.QWebView.stop()

Convenience slot that stops loading the document.

It is equivalent to

view.page().triggerPageAction(QWebPage.Stop)
PySide.QtWebKit.QWebView.textSizeMultiplier()
Return type:PySide.QtCore.qreal

This property holds the scaling factor for all text in the frame.

Use setZoomFactor instead, in combination with the ZoomTextOnly attribute in PySide.QtWebKit.QWebSettings .

Note

Setting this property also enables the ZoomTextOnly attribute in PySide.QtWebKit.QWebSettings .

By default, this property contains a value of 1.0.

PySide.QtWebKit.QWebView.title()
Return type:unicode

This property holds the title of the web page currently viewed.

By default, this property contains an empty string.

PySide.QtWebKit.QWebView.titleChanged(title)
Parameters:title – unicode
PySide.QtWebKit.QWebView.triggerPageAction(action[, checked=false])
Parameters:
PySide.QtWebKit.QWebView.url()
Return type:PySide.QtCore.QUrl

This property holds the url of the web page currently viewed.

Setting this property clears the view and loads the URL.

By default, this property contains an empty, invalid URL.

PySide.QtWebKit.QWebView.urlChanged(arg__1)
Parameters:arg__1PySide.QtCore.QUrl
PySide.QtWebKit.QWebView.zoomFactor()
Return type:PySide.QtCore.qreal

This property holds the zoom factor for the view.