PySide6.QtWebView.QWebView

class QWebView

The QWebView class provides a window that is used to view web content.

Details

A web view is a window for displaying web content that is implemented using native APIs on the platforms where they are available. Therefore, it does not necessarily require including a full web browser stack as part of the application.

A web site can be loaded to a web view with the setUrl() function.

Alternatively, if you have the HTML content readily available, you can use setHtml() instead.

The loadingChanged() signal is emitted when the view begins loading and when the view has been loaded completely. Its argument QWebViewLoadRequest object indicates whether loading was successful or failed.

The title of an HTML document can be accessed with the title() property.

Inheritance diagram of PySide6.QtWebView.QWebView

Added in version 6.11.

Synopsis

Properties

Methods

Slots

Signals

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Note

Properties can be used directly when from __feature__ import true_property is used or via accessor functions otherwise.

property httpUserAgentStringᅟ: str

This property holds The user agent in use. The user-agent string sent with HTTP to identify the browser..

Access functions:
property loadProgressᅟ: int

The current load progress of the web content, represented as an integer between 0 and 100.

Access functions:
property loadingᅟ: bool

Holds true if the WebView is currently in the process of loading new content, false otherwise.

Access functions:
property settingsᅟ: QWebViewSettings

This property holds Settings object for the QWebView . The settings for a web view..

See also

WebViewSettings

Access functions:
property titleᅟ: str

This property holds The title of the currently loaded web page..

The title of the page as defined by the HTML <title> element.

See also

titleChanged()

Access functions:
property urlᅟ: 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. URLs that originate from user input should be parsed with QUrl::fromUserInput().

Note

QWebView does not support loading content through the Qt Resource system.

See also

loadingChanged()

Access functions:
__init__([screen=None])
Parameters:

screenQScreen

__init__(parent)
Parameters:

parentQWindow

canGoBack()
Return type:

bool

Returns true if it’s currently possible to navigate back in the web history.

canGoForward()
Return type:

bool

Returns true if it’s currently possible to navigate forward in the web history.

cookieAdded(domain, name)
Parameters:
  • domain – str

  • name – str

cookieRemoved(domain, name)
Parameters:
  • domain – str

  • name – str

deleteAllCookies()

Deletes all the cookies.

deleteCookie(domain, name)
Parameters:
  • domain – str

  • name – str

goBack()

Navigates back in the web history.

goForward()

Navigates forward in the web history.

httpUserAgentString()
Return type:

str

Getter of property httpUserAgentStringᅟ .

httpUserAgentStringChanged(userAgent)
Parameters:

userAgent – str

This signal is emitted whenever the userAgent of the view changes.

See also

httpUserAgent()

Notification signal of property httpUserAgentStringᅟ .

isLoading()
Return type:

bool

Getter of property loadingᅟ .

loadHtml(html[, baseUrl=QUrl()])
Parameters:
  • html – str

  • baseUrlQUrl

Loads the specified html content to the web view.

This method offers a lower-level alternative to the url property, which references HTML pages via URL.

External objects such as stylesheets or images referenced in the HTML document should be located relative to baseUrl. For example, if html is retrieved from http://www.example.com/documents/overview.html, which is the base URL, then an image referenced with the relative URL diagram.png, should be at http://www.example.com/documents/diagram.png.

Note

The QWebView does not support loading content through the Qt Resource system.

loadProgress()
Return type:

int

Getter of property loadProgressᅟ .

loadProgressChanged(loadProgress)
Parameters:

loadProgress – int

This signal is continuously emitted during the loading of a web page. The loadProgress parameter is a value between 0 and 100, indicating what percentage of the web page has been loaded. The intended use for this is to display a progress bar to the user.

Note

Some backends do not support fractional load progress changes, and will only emit this signal at the start and end of a load, with values of 0 and 100, respecively.

See also

loadingChanged

Notification signal of property loadProgressᅟ .

loadingChanged(loadingInfo)
Parameters:

loadingInfoQWebViewLoadingInfo

This signal is emitted when the state of loading the web content changes. By handling this signal it’s possible, for example, to react to page load errors.

The loadingInfo parameter holds the url and status of the request, as well as an errorString containing an error message for a failed request.

Notification signal of property loadingᅟ .

reload()

Reloads the current url .

runJavaScript(scriptSource, resultCallback)
Parameters:
  • scriptSource – str

  • resultCallbackPyCallable

setCookie(domain, name, value)
Parameters:
  • domain – str

  • name – str

  • value – str

setHttpUserAgentString(httpUserAgent)
Parameters:

httpUserAgent – str

Setter of property httpUserAgentStringᅟ .

setUrl(url)
Parameters:

urlQUrl

See also

url()

Setter of property urlᅟ .

settings()
Return type:

QWebViewSettings

Getter of property settingsᅟ .

stop()

Stops loading the current url .

titleChanged(title)
Parameters:

title – str

This signal is emitted whenever the title of the view changes.

See also

title()

Notification signal of property titleᅟ .

url()
Return type:

QUrl

See also

setUrl()

Getter of property urlᅟ .

urlChanged(url)
Parameters:

urlQUrl

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

See also

url()

Notification signal of property urlᅟ .