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.
The image below shows PySide.QtWebKit.QWebView previewed in Qt Designer with a Nokia website.
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.
PySide.QtWebKit.QWebView consists of other objects such as PySide.QtWebKit.QWebFrame and PySide.QtWebKit.QWebPage . The flowchart below shows these elements are related.
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
Parameters: | parent – PySide.QtGui.QWidget |
---|
Constructs an empty PySide.QtWebKit.QWebView with parent parent .
See also
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)
Parameters: | type – PySide.QtWebKit.QWebPage.WebWindowType |
---|---|
Return type: | PySide.QtWebKit.QWebView |
Parameters: |
|
---|---|
Return type: | PySide.QtCore.bool |
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)
Return type: | PySide.QtWebKit.QWebHistory |
---|
Returns a pointer to the view’s history of navigated web pages.
It is equivalent to
view.page().history()
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.
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.
Parameters: | arg__1 – PySide.QtCore.QUrl |
---|
Parameters: | url – PySide.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 .
See also
PySide.QtWebKit.QWebView.setUrl() PySide.QtWebKit.QWebView.url() PySide.QtWebKit.QWebView.urlChanged() QUrl.fromUserInput()
Parameters: |
|
---|
Parameters: | arg__1 – PySide.QtCore.bool |
---|
Parameters: | progress – PySide.QtCore.int |
---|
Return type: | PySide.QtWebKit.QWebPage |
---|
Returns a pointer to the underlying web page.
See also
Parameters: | action – PySide.QtWebKit.QWebPage.WebAction |
---|---|
Return type: | PySide.QtGui.QAction |
Parameters: | arg__1 – PySide.QtGui.QPrinter |
---|
Prints the main frame to the given printer .
See also
QWebFrame.print() PySide.QtGui.QPrintPreviewDialog
Reloads the current document.
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 is 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()
Return type: | unicode |
---|
This property holds the text currently selected.
By default, this property contains an empty string.
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.
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.
Parameters: | page – PySide.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 document is a child of the web view, it will be deleted.
See also
Parameters: |
|
---|
Parameters: | hints – 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 is 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()
Parameters: | factor – 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.
Parameters: | url – 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.
Parameters: | factor – PySide.QtCore.qreal |
---|
This property holds the zoom factor for the view.
Return type: | PySide.QtWebKit.QWebSettings |
---|
Returns a pointer to the view/page specific settings object.
It is equivalent to
view.page().settings()
See also
Parameters: | text – unicode |
---|
Convenience slot that stops loading the document.
It is equivalent to
view.page().triggerPageAction(QWebPage.Stop)
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.
Return type: | unicode |
---|
This property holds the title of the web page currently viewed.
By default, this property contains an empty string.
Parameters: | title – unicode |
---|
Parameters: |
|
---|
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.
Parameters: | arg__1 – PySide.QtCore.QUrl |
---|
Return type: | PySide.QtCore.qreal |
---|
This property holds the zoom factor for the view.