QWebEnginePage¶
The
QWebEnginePage
class provides an object to view and edit web documents. More…
Synopsis¶
Functions¶
def
action
(action)def
backgroundColor
()def
contentsSize
()def
contextMenuData
()def
createStandardContextMenu
()def
devToolsPage
()def
download
(url[, filename=””])def
findText
(arg__1, arg__2, arg__3)def
findText
(subString[, options=QWebEnginePage.FindFlags()])def
hasSelection
()def
history
()def
icon
()def
iconUrl
()def
inspectedPage
()def
isAudioMuted
()def
isVisible
()def
lifecycleState
()def
load
(request)def
load
(url)def
print
(arg__1, arg__2)def
printToPdf
(arg__1, arg__2)def
printToPdf
(filePath[, layout=QPageLayout(QPageSize(QPageSize.A4), QPageLayout.Portrait, QMarginsF())])def
profile
()def
recentlyAudible
()def
recommendedState
()def
renderProcessPid
()def
replaceMisspelledWord
(replacement)def
requestedUrl
()def
runJavaScript
(arg__1, arg__2, arg__3)def
runJavaScript
(scriptSource)def
runJavaScript
(scriptSource, worldId)def
save
(filePath[, format=QWebEngineDownloadItem.MimeHtmlSaveFormat])def
scripts
()def
scrollPosition
()def
selectedText
()def
setAudioMuted
(muted)def
setBackgroundColor
(color)def
setContent
(data[, mimeType=””[, baseUrl=QUrl()]])def
setDevToolsPage
(page)def
setFeaturePermission
(securityOrigin, feature, policy)def
setHtml
(html[, baseUrl=QUrl()])def
setInspectedPage
(page)def
setLifecycleState
(state)def
setUrl
(url)def
setUrlRequestInterceptor
(interceptor)def
setView
(view)def
setVisible
(visible)def
setWebChannel
(arg__1)def
setWebChannel
(arg__1, worldId)def
setZoomFactor
(factor)def
settings
()def
title
()def
toHtml
(arg__1)def
toPlainText
(arg__1)def
url
()def
view
()def
webChannel
()def
zoomFactor
()
Virtual functions¶
def
acceptNavigationRequest
(url, type, isMainFrame)def
certificateError
(certificateError)def
chooseFiles
(mode, oldFiles, acceptedMimeTypes)def
createWindow
(type)def
javaScriptAlert
(securityOrigin, msg)def
javaScriptConfirm
(securityOrigin, msg)def
javaScriptConsoleMessage
(level, message, lineNumber, sourceID)def
javaScriptPrompt
(securityOrigin, msg, defaultValue, result)def
triggerAction
(action[, checked=false])
Signals¶
def
audioMutedChanged
(muted)def
authenticationRequired
(requestUrl, authenticator)def
contentsSizeChanged
(size)def
featurePermissionRequestCanceled
(securityOrigin, feature)def
featurePermissionRequested
(securityOrigin, feature)def
fullScreenRequested
(fullScreenRequest)def
geometryChangeRequested
(geom)def
iconChanged
(icon)def
iconUrlChanged
(url)def
lifecycleStateChanged
(state)def
linkHovered
(url)def
loadFinished
(ok)def
loadProgress
(progress)def
loadStarted
()def
pdfPrintingFinished
(filePath, success)def
printRequested
()def
proxyAuthenticationRequired
(requestUrl, authenticator, proxyHost)def
recentlyAudibleChanged
(recentlyAudible)def
recommendedStateChanged
(state)def
renderProcessPidChanged
(pid)def
renderProcessTerminated
(terminationStatus, exitCode)def
scrollPositionChanged
(position)def
selectionChanged
()def
titleChanged
(title)def
urlChanged
(url)def
visibleChanged
(visible)def
windowCloseRequested
()
Detailed Description¶
A web engine page holds the contents of an HTML document, the history of navigated links, and actions.
QWebEnginePage
‘s API is very similar toQWebEngineView
, as you are still provided with common functions likeaction()
(known aspageAction
() inQWebEngineView
),triggerAction()
, andfindText()
.A page can be loaded using
load()
orsetUrl()
. Alternatively, if you have the HTML content readily available, you can usesetHtml()
. The GET method is always used to load URLs.The
QWebEnginePage
class also offers methods to retrieve both the URL currently loaded by the page (seeurl()
) as well as the URL originally requested to be loaded (seerequestedUrl()
). These methods make possible the retrieval of the URL before and after a DNS resolution or a redirection occurs during the load process. TherequestedUrl()
also matches to the URL added to the page history (QWebEngineHistory
) if load is successful.The title of an HTML page can be accessed with the
title()
property. Additionally, a page may also specify an icon, which can be accessed using theicon()
or its URL using theiconUrl()
property. If the title or the icon changes, the correspondingtitleChanged()
,iconChanged()
andiconUrlChanged()
signals will be emitted. ThezoomFactor()
property enables zooming the contents of the web page by a scale factor.The
loadStarted()
signal is emitted when the page begins to load, whereas theloadProgress()
signal is emitted whenever an element of the web page completes loading, such as an embedded image or a script. TheloadFinished()
signal is emitted when the page contents have been loaded completely, independent of script execution or page rendering. Its argument, eithertrue
orfalse
, indicates whether or not the load operation succeeded.An HTML document is loaded in a main frame within the web page. If it references child frames (as defined by the
<frame>
or<iframe>
elements), they are considered part of the content. Child frames are individually accessible only through JavaScript.Web sites define security origin for safely accessing each other’s resources for client-side scripting or databases. An origin consist of a host name, a scheme, and a port number. For example, the sites
http://www.example.com/my/page.html
andhttp://www.example.com/my/overview.html
are allowed to share the same database or access each other’s documents when used in HTML frame sets and JavaScript. At the same time,http://www.malicious.com/evil.html
is prevented from accessing the resources ofhttp://www.example.com/
, because they are of a different security origin. By default, local schemes likefile://
andqrc://
are considered to be in the same security origin, and can access each other’s resources. Local resources are by default restricted from accessing remote content, which means thatfile://
will not be able to accesshttp://domain.com/foo.html
.Scripts can be executed on the web page by using
runJavaScript()
, either in the main JavaScript world , along with the rest of the JavaScript coming from the web contents, or in their own isolated world. While the DOM of the page can be accessed from any world, JavaScript variables of a function defined in one world are not accessible from a different one.ScriptWorldId
provides some predefined IDs for this purpose. Using therunJavaScript()
version without the world ID is the same as running the script in theMainWorld
.The
FocusOnNavigationEnabled
setting can be used to make the view associated with the page automatically receive focus when a navigation operation occurs (like loading or reloading a page or navigating through history).
- class PySide2.QtWebEngineWidgets.QWebEnginePage([parent=Q_NULLPTR])¶
PySide2.QtWebEngineWidgets.QWebEnginePage(profile[, parent=Q_NULLPTR])
- param parent:
- param profile:
Constructs an empty
QWebEnginePage
with the parentparent
.Constructs an empty web engine page in the web engine profile
profile
with the parentparent
.If the profile is not the default profile, the caller must ensure that the profile stays alive for as long as the page does.
- PySide2.QtWebEngineWidgets.QWebEnginePage.WebAction¶
This enum describes the types of action which can be performed on the web page.
Actions only have an effect when they are applicable.
The availability of actions can be be determined by checking
isEnabled()
on the action returned byaction()
.Constant
Description
QWebEnginePage.NoWebAction
No action is triggered.
QWebEnginePage.Back
Navigate back in the history of navigated links.
QWebEnginePage.Forward
Navigate forward in the history of navigated links.
QWebEnginePage.Stop
Stop loading the current page.
QWebEnginePage.Reload
Reload the current page.
QWebEnginePage.ReloadAndBypassCache
Reload the current page, but do not use any local cache.
QWebEnginePage.Cut
Cut the content currently selected into the clipboard.
QWebEnginePage.Copy
Copy the content currently selected into the clipboard.
QWebEnginePage.Paste
Paste content from the clipboard.
QWebEnginePage.Undo
Undo the last editing action.
QWebEnginePage.Redo
Redo the last editing action.
QWebEnginePage.SelectAll
Select all content. This action is only enabled when the page’s content is focused. The focus can be forced by the JavaScript
window.focus()
call, or theFocusOnNavigationEnabled
setting should be enabled to get automatic focus.QWebEnginePage.PasteAndMatchStyle
Paste content from the clipboard with current style.
QWebEnginePage.OpenLinkInThisWindow
Open the current link in the current window. (Added in Qt 5.6)
QWebEnginePage.OpenLinkInNewWindow
Open the current link in a new window. Requires implementation of
createWindow()
. (Added in Qt 5.6)QWebEnginePage.OpenLinkInNewTab
Open the current link in a new tab. Requires implementation of
createWindow()
. (Added in Qt 5.6)QWebEnginePage.OpenLinkInNewBackgroundTab
Open the current link in a new background tab. Requires implementation of
createWindow()
. (Added in Qt 5.7)QWebEnginePage.CopyLinkToClipboard
Copy the current link to the clipboard. (Added in Qt 5.6)
QWebEnginePage.CopyImageToClipboard
Copy the clicked image to the clipboard. (Added in Qt 5.6)
QWebEnginePage.CopyImageUrlToClipboard
Copy the clicked image’s URL to the clipboard. (Added in Qt 5.6)
QWebEnginePage.CopyMediaUrlToClipboard
Copy the hovered audio or video’s URL to the clipboard. (Added in Qt 5.6)
QWebEnginePage.ToggleMediaControls
Toggle between showing and hiding the controls for the hovered audio or video element. (Added in Qt 5.6)
QWebEnginePage.ToggleMediaLoop
Toggle whether the hovered audio or video should loop on completetion or not. (Added in Qt 5.6)
QWebEnginePage.ToggleMediaPlayPause
Toggle the play/pause state of the hovered audio or video element. (Added in Qt 5.6)
QWebEnginePage.ToggleMediaMute
Mute or unmute the hovered audio or video element. (Added in Qt 5.6)
QWebEnginePage.DownloadLinkToDisk
Download the current link to the disk. Requires a slot for
downloadRequested()
. (Added in Qt 5.6)QWebEnginePage.DownloadImageToDisk
Download the highlighted image to the disk. Requires a slot for
downloadRequested()
. (Added in Qt 5.6)QWebEnginePage.DownloadMediaToDisk
Download the hovered audio or video to the disk. Requires a slot for
downloadRequested()
. (Added in Qt 5.6)QWebEnginePage.InspectElement
Trigger any attached Web Inspector to inspect the highlighed element. (Added in Qt 5.6)
QWebEnginePage.ExitFullScreen
Exit the fullscreen mode. (Added in Qt 5.6)
QWebEnginePage.RequestClose
Request to close the web page. If defined, the
window.onbeforeunload
handler is run, and the user can confirm or reject to close the page. If the close request is confirmed,windowCloseRequested
is emitted. (Added in Qt 5.6)QWebEnginePage.Unselect
Clear the current selection. (Added in Qt 5.7)
QWebEnginePage.SavePage
Save the current page to disk. MHTML is the default format that is used to store the web page on disk. Requires a slot for
downloadRequested()
. (Added in Qt 5.7)QWebEnginePage.ViewSource
Show the source of the current page in a new tab. Requires implementation of
createWindow()
. (Added in Qt 5.8)QWebEnginePage.ToggleBold
Toggles boldness for the selection or at the cursor position. Requires
contenteditable="true"
. (Added in Qt 5.10)QWebEnginePage.ToggleItalic
Toggles italics for the selection or at the cursor position. Requires
contenteditable="true"
. (Added in Qt 5.10)QWebEnginePage.ToggleUnderline
Toggles underlining of the selection or at the cursor position. Requires
contenteditable="true"
. (Added in Qt 5.10)QWebEnginePage.ToggleStrikethrough
Toggles striking through the selection or at the cursor position. Requires
contenteditable="true"
. (Added in Qt 5.10)QWebEnginePage.AlignLeft
Aligns the lines containing the selection or the cursor to the left. Requires
contenteditable="true"
. (Added in Qt 5.10)QWebEnginePage.AlignCenter
Aligns the lines containing the selection or the cursor at the center. Requires
contenteditable="true"
. (Added in Qt 5.10)QWebEnginePage.AlignRight
Aligns the lines containing the selection or the cursor to the right. Requires
contenteditable="true"
. (Added in Qt 5.10)QWebEnginePage.AlignJustified
Stretches the lines containing the selection or the cursor so that each line has equal width. Requires
contenteditable="true"
. (Added in Qt 5.10)QWebEnginePage.Indent
Indents the lines containing the selection or the cursor. Requires
contenteditable="true"
. (Added in Qt 5.10)QWebEnginePage.Outdent
Outdents the lines containing the selection or the cursor. Requires
contenteditable="true"
. (Added in Qt 5.10)QWebEnginePage.InsertOrderedList
Inserts an ordered list at the current cursor position, deleting the current selection. Requires
contenteditable="true"
. (Added in Qt 5.10)QWebEnginePage.InsertUnorderedList
Inserts an unordered list at the current cursor position, deleting the current selection. Requires
contenteditable="true"
. (Added in Qt 5.10)
- PySide2.QtWebEngineWidgets.QWebEnginePage.FindFlag¶
This enum describes the options available to the
findText()
function. The options can be OR-ed together from the following list:Constant
Description
QWebEnginePage.FindBackward
Searches backwards instead of forwards.
QWebEnginePage.FindCaseSensitively
By default
findText()
works case insensitive. Specifying this option changes the behavior to a case sensitive find operation.
- PySide2.QtWebEngineWidgets.QWebEnginePage.WebWindowType¶
This enum describes the types of window that can be created by the
createWindow()
function:Constant
Description
QWebEnginePage.WebBrowserWindow
A complete web browser window.
QWebEnginePage.WebBrowserTab
A web browser tab.
QWebEnginePage.WebDialog
A window without decoration.
QWebEnginePage.WebBrowserBackgroundTab
A web browser tab without hiding the current visible WebEngineView . (Added in Qt 5.7)
- PySide2.QtWebEngineWidgets.QWebEnginePage.PermissionPolicy¶
This enum describes the permission policies that the user may set for data or device access:
Constant
Description
QWebEnginePage.PermissionUnknown
It is unknown whether the user grants or denies permission.
QWebEnginePage.PermissionGrantedByUser
The user has granted permission.
QWebEnginePage.PermissionDeniedByUser
The user has denied permission.
This enum describes the type of a navigation request:
Constant
Description
QWebEnginePage.NavigationTypeLinkClicked
The navigation request resulted from a clicked link.
QWebEnginePage.NavigationTypeTyped
The navigation request resulted from an explicitly loaded URL.
QWebEnginePage.NavigationTypeFormSubmitted
The navigation request resulted from a form submission.
QWebEnginePage.NavigationTypeBackForward
The navigation request resulted from a back or forward action.
QWebEnginePage.NavigationTypeReload
The navigation request resulted from a reload action.
QWebEnginePage.NavigationTypeRedirect
The navigation request resulted from a content or server controlled redirect. This also includes automatic reloads. (Added in Qt 5.14)
QWebEnginePage.NavigationTypeOther
The navigation request was triggered by other means not covered by the above.
See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.Feature¶
This enum describes the platform feature access categories that the user may be asked to grant or deny access to:
Constant
Description
QWebEnginePage.Notifications
Web notifications for the end-user.
QWebEnginePage.Geolocation
Location hardware or service.
QWebEnginePage.MediaAudioCapture
Audio capture devices, such as microphones.
QWebEnginePage.MediaVideoCapture
Video devices, such as cameras.
QWebEnginePage.MediaAudioVideoCapture
Both audio and video capture devices.
QWebEnginePage.MouseLock
Mouse locking, which locks the mouse pointer to the web view and is typically used in games.
QWebEnginePage.DesktopVideoCapture
Video output capture, that is, the capture of the user’s display, for screen sharing purposes for example. (Added in Qt 5.10)
QWebEnginePage.DesktopAudioVideoCapture
Both audio and video output capture. (Added in Qt 5.10)
See also
featurePermissionRequested()
featurePermissionRequestCanceled()
setFeaturePermission()
PermissionPolicy
- PySide2.QtWebEngineWidgets.QWebEnginePage.FileSelectionMode¶
This enum indicates whether the implementation of the
chooseFiles()
function should return only one file or may return multiple files:Constant
Description
QWebEnginePage.FileSelectOpen
Return only one file name.
QWebEnginePage.FileSelectOpenMultiple
Return multiple file names.
See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.JavaScriptConsoleMessageLevel¶
This enum describes the different severity levels a JavaScript console message can have:
Constant
Description
QWebEnginePage.InfoMessageLevel
The message is purely informative and can safely be ignored.
QWebEnginePage.WarningMessageLevel
The message informs about unexpected behavior or errors that may need attention.
QWebEnginePage.ErrorMessageLevel
The message indicates there has been an error.
- PySide2.QtWebEngineWidgets.QWebEnginePage.RenderProcessTerminationStatus¶
This enum describes the status with which the render process terminated:
Constant
Description
QWebEnginePage.NormalTerminationStatus
The render process terminated normally.
QWebEnginePage.AbnormalTerminationStatus
The render process terminated with with a non-zero exit status.
QWebEnginePage.CrashedTerminationStatus
The render process crashed, for example because of a segmentation fault.
QWebEnginePage.KilledTerminationStatus
The render process was killed, for example by
SIGKILL
or task manager kill.
- PySide2.QtWebEngineWidgets.QWebEnginePage.LifecycleState¶
This enum describes the lifecycle state of the page:
Constant
Description
QWebEnginePage.LifecycleState.Active
Normal state.
QWebEnginePage.LifecycleState.Frozen
Low CPU usage state where most HTML task sources are suspended.
QWebEnginePage.LifecycleState.Discarded
Very low resource usage state where the entire browsing context is discarded.
See also
lifecycleState
Page Lifecycle API WebEngine Lifecycle Example
- Parameters:
url –
PySide2.QtCore.QUrl
type –
NavigationType
isMainFrame – bool
- Return type:
bool
This function is called upon receiving a request to navigate to the specified
url
by means of the specified navigation typetype
.isMainFrame
indicates whether the request corresponds to the main frame or a child frame. If the function returnstrue
, the navigation request is accepted andurl
is loaded. The default implementation accepts all navigation requests.Navigation requests can be delegated to the Qt application instead of having the HTML handler engine process them by overloading this function. This is necessary when an HTML document is used as part of the user interface, and not to display external data, for example, when displaying a list of results.
Note
This function is not called for fragment navigation on the same page. Such navigation, for example, happens by clicking a link to a ‘#fragment’ within the page. It does not trigger a load to a different document, even though it changes page’s url and adds history entry. It only serves as a shortcut to scroll within the page. Hence, no delegation of this navigation type is expected to happen.
Note
The loading process is started and the
loadStarted()
signal is emitted before the request is accepted or rejected. Therefore, aloadFinished()
signal that returnsfalse
is to be expected even after delegating the request.Note
When using
setHtml
orsetContent
with relative links, make sure to specify a base url, otherwise the links will be considered invalid and no navigation requests will be emitted.The
QWebEngineUrlRequestInterceptor
class offers further options for intercepting and manipulating requests.
- PySide2.QtWebEngineWidgets.QWebEnginePage.action(action)¶
- Parameters:
action –
WebAction
- Return type:
Returns a
QAction
for the specifiedWebAction
action
.The action is owned by the
QWebEnginePage
but you can customize the look by changing its properties.QWebEnginePage
also takes care of implementing the action, so that upon triggering the corresponding action is performed on the page.See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.audioMutedChanged(muted)¶
- Parameters:
muted – bool
- PySide2.QtWebEngineWidgets.QWebEnginePage.authenticationRequired(requestUrl, authenticator)¶
- Parameters:
requestUrl –
PySide2.QtCore.QUrl
authenticator –
PySide2.QtNetwork.QAuthenticator
- PySide2.QtWebEngineWidgets.QWebEnginePage.backgroundColor()¶
- Return type:
This property holds The page’s background color behind the document’s body..
You can set the background color to
transparent
or to a translucent color to see through the document, or you can set it to match your web content in a hybrid application to prevent the white flashes that may appear during loading.The default value is white.
- PySide2.QtWebEngineWidgets.QWebEnginePage.certificateError(certificateError)¶
- Parameters:
certificateError –
PySide2.QtWebEngineWidgets.QWebEngineCertificateError
- Return type:
bool
This function is called when an invalid certificate error is raised while loading a given request.
The
certificateError
parameter contains information about the certificate and details of the error.Return
true
to ignore the error and complete the request. Returnfalse
to stop loading the request.Note
If the error was successfully deferred then the returned value will be ignored.
See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.chooseFiles(mode, oldFiles, acceptedMimeTypes)¶
- Parameters:
mode –
FileSelectionMode
oldFiles – list of strings
acceptedMimeTypes – list of strings
- Return type:
list of strings
This function is called when the web content requests a file name, for example as a result of the user clicking on a file upload button in an HTML form.
mode
indicates whether only one file or multiple files are expected to be returned.A suggested filename may be provided as the first entry of
oldFiles
.acceptedMimeTypes
is ignored by the default implementation, but might be used by overrides.
- PySide2.QtWebEngineWidgets.QWebEnginePage.contentsSize()¶
- Return type:
This property holds The size of the page contents..
- PySide2.QtWebEngineWidgets.QWebEnginePage.contentsSizeChanged(size)¶
- Parameters:
size –
PySide2.QtCore.QSizeF
- PySide2.QtWebEngineWidgets.QWebEnginePage.contextMenuData()¶
- Return type:
Returns additional data about the current context menu. It is only guaranteed to be valid during the call to the
contextMenuEvent()
handler of the associatedQWebEngineView
.See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.createStandardContextMenu()¶
- Return type:
Creates the standard context menu which is shown when the user clicks on the web page with the right mouse button. It is called from the default
contextMenuEvent()
handler. The popup menu’s ownership is transferred to the caller.Returns
nullptr
if the context menu data is not initialized, for example when it is called when there is actually no context menu requested.
- PySide2.QtWebEngineWidgets.QWebEnginePage.createWindow(type)¶
- Parameters:
type –
WebWindowType
- Return type:
This function is called to create a new window of the specified
type
. For example, when a JavaScript program requests to open a document in a new window.If the new window can be created, the new window’s
QWebEnginePage
is returned; otherwise a null pointer is returned.If the view associated with the web page is a
QWebEngineView
object, then the default implementation forwards the request tocreateWindow()
; otherwise it returns a null pointer.Note
In the cases when the window creation is being triggered by JavaScript, apart from reimplementing this method the application must also set
JavascriptCanOpenWindows
totrue
in order for the method to get called.See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.devToolsPage()¶
- Return type:
Returns the page that is hosting the developer tools of this page, if any.
Returns
nullptr
if no developer tools page is set.See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.download(url[, filename=""])¶
- Parameters:
url –
PySide2.QtCore.QUrl
filename – str
Downloads the resource from the location given by
url
to a local file.If
filename
is given, it is used as the suggested file name. If it is relative, the file is saved in the standard download location with the given name. If it is a null or emptyQString
, the default file name is used.This will emit
downloadRequested()
after the download has started.
- PySide2.QtWebEngineWidgets.QWebEnginePage.featurePermissionRequestCanceled(securityOrigin, feature)¶
- Parameters:
securityOrigin –
PySide2.QtCore.QUrl
feature –
Feature
- PySide2.QtWebEngineWidgets.QWebEnginePage.featurePermissionRequested(securityOrigin, feature)¶
- Parameters:
securityOrigin –
PySide2.QtCore.QUrl
feature –
Feature
- PySide2.QtWebEngineWidgets.QWebEnginePage.findText(arg__1, arg__2, arg__3)¶
- Parameters:
arg__1 – str
arg__2 –
FindFlags
arg__3 – object
- PySide2.QtWebEngineWidgets.QWebEnginePage.findText(subString[, options=QWebEnginePage.FindFlags()])
- Parameters:
subString – str
options –
FindFlags
- PySide2.QtWebEngineWidgets.QWebEnginePage.fullScreenRequested(fullScreenRequest)¶
- Parameters:
fullScreenRequest –
PySide2.QtWebEngineWidgets.QWebEngineFullScreenRequest
- PySide2.QtWebEngineWidgets.QWebEnginePage.geometryChangeRequested(geom)¶
- Parameters:
geom –
PySide2.QtCore.QRect
- PySide2.QtWebEngineWidgets.QWebEnginePage.hasSelection()¶
- Return type:
bool
This property holds Whether this page contains selected content or not..
See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.history()¶
- Return type:
Returns a pointer to the view’s history of navigated web pages.
- PySide2.QtWebEngineWidgets.QWebEnginePage.icon()¶
- Return type:
This property holds The icon associated with the page currently viewed..
By default, this property contains a null icon. If the web page specifies more than one icon, the
icon
property encapsulates the available candidate icons in a single, scalableQIcon
.See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.iconChanged(icon)¶
- Parameters:
icon –
PySide2.QtGui.QIcon
- PySide2.QtWebEngineWidgets.QWebEnginePage.iconUrl()¶
- Return type:
This property holds The URL of the icon associated with the page currently viewed..
By default, this property contains an empty URL.
See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.iconUrlChanged(url)¶
- Parameters:
url –
PySide2.QtCore.QUrl
- PySide2.QtWebEngineWidgets.QWebEnginePage.inspectedPage()¶
- Return type:
Returns the page this page is inspecting, if any.
Returns
nullptr
if this page is not a developer tools page.See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.isAudioMuted()¶
- Return type:
bool
This property holds Whether the current page audio is muted..
The default value is
false
.See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.isVisible()¶
- Return type:
bool
This property holds Whether the page is considered visible in the Page Visibility API..
Setting this property changes the
Document.hidden
and theDocument.visibilityState
properties in JavaScript which web sites can use to voluntarily reduce their resource usage if they are not visible to the user.If the page is connected to a
view
then this property will be managed automatically by the view according to it’s own visibility.See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.javaScriptAlert(securityOrigin, msg)¶
- Parameters:
securityOrigin –
PySide2.QtCore.QUrl
msg – str
This function is called whenever a JavaScript program running in a frame affiliated with
securityOrigin
calls thealert()
function with the messagemsg
.The default implementation shows the message,
msg
, withinformation
.
- PySide2.QtWebEngineWidgets.QWebEnginePage.javaScriptConfirm(securityOrigin, msg)¶
- Parameters:
securityOrigin –
PySide2.QtCore.QUrl
msg – str
- Return type:
bool
This function is called whenever a JavaScript program running in a frame affiliated with
securityOrigin
calls theconfirm()
function with the messagemsg
. Returnstrue
if the user confirms the message; otherwise returnsfalse
.It is also called when the
onbeforeunload
handler is requesting a confirmation before leaving a page.The default implementation executes the query using
information
withOk
andCancel
buttons.
- PySide2.QtWebEngineWidgets.QWebEnginePage.javaScriptConsoleMessage(level, message, lineNumber, sourceID)¶
- Parameters:
level –
JavaScriptConsoleMessageLevel
message – str
lineNumber – int
sourceID – str
This function is called when a JavaScript program tries to print the
message
to the web browser’s console.For example, in case of evaluation errors the source URL may be provided in
sourceID
as well as thelineNumber
.level
indicates the severity of the event that triggered the message. That is, whether it was triggered by an error or a less severe event.Since Qt 5.6, the default implementation logs the messages in a
js
logging category
.See also
Console Logging
- PySide2.QtWebEngineWidgets.QWebEnginePage.javaScriptPrompt(securityOrigin, msg, defaultValue, result)¶
- Parameters:
securityOrigin –
PySide2.QtCore.QUrl
msg – str
defaultValue – str
result – str
- Return type:
bool
This function is called whenever a JavaScript program running in a frame affiliated with
securityOrigin
tries to prompt the user for input. The program may provide an optional message,msg
, as well as a default value for the input indefaultValue
.If the prompt was cancelled by the user, the implementation should return
false
; otherwise the result should be written toresult
andtrue
should be returned. If the prompt was not cancelled by the user, the implementation should returntrue
and the result string must not be null.The default implementation uses
getText()
.
- PySide2.QtWebEngineWidgets.QWebEnginePage.lifecycleState()¶
- Return type:
This property holds The current lifecycle state of the page..
The following restrictions are enforced by the setter:
A
visible
page must remain in theActive
state.If the page is being inspected by a
devToolsPage
then both pages must remain in theActive
states.A page in the
Discarded
state can only transition to theActive
state. This will cause a reload of the page.
These are the only hard limits on the lifecycle state, but see also
recommendedState
for the recommended soft limits.See also
recommendedState
Page Lifecycle API WebEngine Lifecycle Example
- PySide2.QtWebEngineWidgets.QWebEnginePage.lifecycleStateChanged(state)¶
- Parameters:
state –
LifecycleState
- PySide2.QtWebEngineWidgets.QWebEnginePage.linkHovered(url)¶
- Parameters:
url – str
- PySide2.QtWebEngineWidgets.QWebEnginePage.load(url)¶
- Parameters:
url –
PySide2.QtCore.QUrl
- PySide2.QtWebEngineWidgets.QWebEnginePage.load(request)
- Parameters:
- PySide2.QtWebEngineWidgets.QWebEnginePage.loadFinished(ok)¶
- Parameters:
ok – bool
- PySide2.QtWebEngineWidgets.QWebEnginePage.loadProgress(progress)¶
- Parameters:
progress – int
- PySide2.QtWebEngineWidgets.QWebEnginePage.loadStarted()¶
- PySide2.QtWebEngineWidgets.QWebEnginePage.pdfPrintingFinished(filePath, success)¶
- Parameters:
filePath – str
success – bool
- PySide2.QtWebEngineWidgets.QWebEnginePage.print(arg__1, arg__2)¶
- Parameters:
arg__1 –
PySide2.QtPrintSupport.QPrinter
arg__2 – object
- PySide2.QtWebEngineWidgets.QWebEnginePage.printRequested()¶
- PySide2.QtWebEngineWidgets.QWebEnginePage.printToPdf(arg__1, arg__2)¶
- Parameters:
arg__1 – object
arg__2 –
PySide2.QtGui.QPageLayout
- PySide2.QtWebEngineWidgets.QWebEnginePage.printToPdf(filePath[, layout=QPageLayout(QPageSize(QPageSize.A4), QPageLayout.Portrait, QMarginsF())])
- Parameters:
filePath – str
layout –
PySide2.QtGui.QPageLayout
- PySide2.QtWebEngineWidgets.QWebEnginePage.profile()¶
- Return type:
Returns the web engine profile the page belongs to.
- PySide2.QtWebEngineWidgets.QWebEnginePage.proxyAuthenticationRequired(requestUrl, authenticator, proxyHost)¶
- Parameters:
requestUrl –
PySide2.QtCore.QUrl
authenticator –
PySide2.QtNetwork.QAuthenticator
proxyHost – str
- PySide2.QtWebEngineWidgets.QWebEnginePage.recentlyAudible()¶
- Return type:
bool
This property holds The current page’s audible state , that is, whether audio was recently played or not..
The default value is
false
.See also
audioMuted
- PySide2.QtWebEngineWidgets.QWebEnginePage.recentlyAudibleChanged(recentlyAudible)¶
- Parameters:
recentlyAudible – bool
- PySide2.QtWebEngineWidgets.QWebEnginePage.recommendedState()¶
- Return type:
This property holds The recommended limit for the lifecycle state of the page..
Setting the lifecycle state to a lower resource usage state than the recommended state may cause side-effects such as stopping background audio playback or loss of HTML form input. Setting the lifecycle state to a higher resource state is however completely safe.
See also
lifecycleState
Page Lifecycle API WebEngine Lifecycle Example
- PySide2.QtWebEngineWidgets.QWebEnginePage.recommendedStateChanged(state)¶
- Parameters:
state –
LifecycleState
- PySide2.QtWebEngineWidgets.QWebEnginePage.renderProcessPid()¶
- Return type:
int
This property holds The process ID (PID) of the render process assigned to the current page’s main frame..
If no render process is available yet,
0
is returned.
- PySide2.QtWebEngineWidgets.QWebEnginePage.renderProcessPidChanged(pid)¶
- Parameters:
pid – int
- PySide2.QtWebEngineWidgets.QWebEnginePage.renderProcessTerminated(terminationStatus, exitCode)¶
- Parameters:
terminationStatus –
RenderProcessTerminationStatus
exitCode – int
- PySide2.QtWebEngineWidgets.QWebEnginePage.replaceMisspelledWord(replacement)¶
- Parameters:
replacement – str
Replace the current misspelled word with
replacement
.The current misspelled word can be found in
misspelledWord()
, and suggested replacements inspellCheckerSuggestions()
.See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.requestedUrl()¶
- Return type:
This property holds The URL that was originally requested to be loaded by the page that is currently viewed..
Note
The URL may differ from the one returned by
url()
, which is the actual URL that results from DNS resolution or redirection.
- PySide2.QtWebEngineWidgets.QWebEnginePage.runJavaScript(arg__1, arg__2, arg__3)¶
- Parameters:
arg__1 – str
arg__2 – int
arg__3 – object
- PySide2.QtWebEngineWidgets.QWebEnginePage.runJavaScript(scriptSource)
- Parameters:
scriptSource – str
- PySide2.QtWebEngineWidgets.QWebEnginePage.runJavaScript(scriptSource, worldId)
- Parameters:
scriptSource – str
worldId – int
- PySide2.QtWebEngineWidgets.QWebEnginePage.save(filePath[, format=QWebEngineDownloadItem.MimeHtmlSaveFormat])¶
- Parameters:
filePath – str
format –
SavePageFormat
Save the currently loaded web page to disk.
The web page is saved to
filePath
in the specifiedformat
.This is a short cut for the following actions:
Trigger the Save web action.
Accept the next download item and set the specified file path and save format.
This function issues an asynchronous download request for the web page and returns immediately.
See also
SavePageFormat
- PySide2.QtWebEngineWidgets.QWebEnginePage.scripts()¶
-
Returns the collection of scripts that are injected into the page.
In addition, a page might also execute scripts added through
scripts()
.See also
QWebEngineScriptCollection
QWebEngineScript
Script Injection
- PySide2.QtWebEngineWidgets.QWebEnginePage.scrollPosition()¶
- Return type:
This property holds The scroll position of the page contents..
- PySide2.QtWebEngineWidgets.QWebEnginePage.scrollPositionChanged(position)¶
- Parameters:
position –
PySide2.QtCore.QPointF
- PySide2.QtWebEngineWidgets.QWebEnginePage.selectedText()¶
- Return type:
str
This property holds The text currently selected..
By default, this property contains an empty string.
See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.selectionChanged()¶
- PySide2.QtWebEngineWidgets.QWebEnginePage.setAudioMuted(muted)¶
- Parameters:
muted – bool
This property holds Whether the current page audio is muted..
The default value is
false
.See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.setBackgroundColor(color)¶
- Parameters:
color –
PySide2.QtGui.QColor
This property holds The page’s background color behind the document’s body..
You can set the background color to
transparent
or to a translucent color to see through the document, or you can set it to match your web content in a hybrid application to prevent the white flashes that may appear during loading.The default value is white.
- PySide2.QtWebEngineWidgets.QWebEnginePage.setContent(data[, mimeType=""[, baseUrl=QUrl()]])¶
- Parameters:
data –
PySide2.QtCore.QByteArray
mimeType – str
baseUrl –
PySide2.QtCore.QUrl
Sets the content of the web page to
data
. If themimeType
argument is empty, it is assumed that the content istext/plain,charset=US-ASCII
.External objects referenced in the content are located relative to
baseUrl
.The
data
is loaded immediately; external objects are loaded asynchronously.Note
This method will not affect session or global history for the page.
Warning
The content will be percent encoded before being sent to the renderer via IPC. This may increase its size. The maximum size of the percent encoded content is 2 megabytes minus 6 bytes plus the length of the mime type string.
- PySide2.QtWebEngineWidgets.QWebEnginePage.setDevToolsPage(page)¶
- Parameters:
Binds
devToolsPage
to be the developer tools of this page. TriggersdevToolsPage
to navigate to an internal URL with the developer tools.This is the same as calling
setInspectedPage()
ondevToolsPage
withthis
as argument.See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.setFeaturePermission(securityOrigin, feature, policy)¶
- Parameters:
securityOrigin –
PySide2.QtCore.QUrl
feature –
Feature
policy –
PermissionPolicy
Sets the permission for the web site identified by
securityOrigin
to usefeature
topolicy
.Note
This method is primarily for calling after a
featurePermissionRequested()
signal has been emitted to trigger the feature permission response. It can also be called before a request has been emitted, but will only set a granted permission for passive checks, mainly for Notification APIs that can check if permission has already been granted before explicitly requesting it.
- PySide2.QtWebEngineWidgets.QWebEnginePage.setHtml(html[, baseUrl=QUrl()])¶
- Parameters:
html – str
baseUrl –
PySide2.QtCore.QUrl
Sets the content of this page to
html
.baseUrl
is optional and used to resolve relative URLs in the document, such as referenced images or stylesheets.The
html
is loaded immediately; external objects are loaded asynchronously.If a script in the
html
runs longer than the default script timeout (currently 10 seconds), for example due to being blocked by a modal JavaScript alert dialog, this method will return as soon as possible after the timeout and any subsequenthtml
will be loaded asynchronously.When using this method, the web engine 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. It is also possible for the encoding to be specified by the web server.
This is a convenience function equivalent to
setContent
(html, “text/html”, baseUrl).Note
This method will not affect session or global history for the page.
Warning
This function works only for HTML, for other mime types (such as XHTML and SVG)
setContent()
should be used instead.Warning
The content will be percent encoded before being sent to the renderer via IPC. This may increase its size. The maximum size of the percent encoded content is 2 megabytes minus 30 bytes.
See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.setInspectedPage(page)¶
- Parameters:
Navigates this page to an internal URL that is the developer tools of
page
.This is the same as calling
setDevToolsPage()
onpage
withthis
as argument.See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.setLifecycleState(state)¶
- Parameters:
state –
LifecycleState
This property holds The current lifecycle state of the page..
The following restrictions are enforced by the setter:
A
visible
page must remain in theActive
state.If the page is being inspected by a
devToolsPage
then both pages must remain in theActive
states.A page in the
Discarded
state can only transition to theActive
state. This will cause a reload of the page.
These are the only hard limits on the lifecycle state, but see also
recommendedState
for the recommended soft limits.See also
recommendedState
Page Lifecycle API WebEngine Lifecycle Example
- PySide2.QtWebEngineWidgets.QWebEnginePage.setUrl(url)¶
- Parameters:
url –
PySide2.QtCore.QUrl
This property holds The URL of the page currently viewed..
Setting this property clears the view and loads the URL.
By default, this property contains an empty, invalid URL.
See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.setUrlRequestInterceptor(interceptor)¶
- Parameters:
interceptor –
PySide2.QtWebEngineCore.QWebEngineUrlRequestInterceptor
Registers the request interceptor
interceptor
to intercept URL requests.The page does not take ownership of the pointer. This interceptor is called after any interceptors on the profile, and unlike profile interceptors, only URL requests from this page are intercepted.
To unset the request interceptor, set a
nullptr
.See also
QWebEngineUrlRequestInfo
setUrlRequestInterceptor()
- PySide2.QtWebEngineWidgets.QWebEnginePage.setView(view)¶
- Parameters:
view –
PySide2.QtWidgets.QWidget
Sets the
view
that is associated with the web page.See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.setVisible(visible)¶
- Parameters:
visible – bool
This property holds Whether the page is considered visible in the Page Visibility API..
Setting this property changes the
Document.hidden
and theDocument.visibilityState
properties in JavaScript which web sites can use to voluntarily reduce their resource usage if they are not visible to the user.If the page is connected to a
view
then this property will be managed automatically by the view according to it’s own visibility.See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.setWebChannel(arg__1)¶
- Parameters:
arg__1 –
PySide2.QtWebChannel.QWebChannel
This is an overloaded function.
Sets the web channel instance to be used by this page to
channel
and installs it in the main JavaScript world.With this method the web channel can be accessed by web page content. If the content is not under your control and might be hostile, this could be a security issue and you should consider installing it in a private JavaScript world.
See also
MainWorld
- PySide2.QtWebEngineWidgets.QWebEnginePage.setWebChannel(arg__1, worldId)
- Parameters:
arg__1 –
PySide2.QtWebChannel.QWebChannel
worldId –
uint
Sets the web channel instance to be used by this page to
channel
and connects it to web engine’s transport using Chromium IPC messages. The transport is exposed in the JavaScript worldworldId
asqt.webChannelTransport
, which should be used when using the Qt WebChannel JavaScript API .Note
The page does not take ownership of the channel object.
Note
Only one web channel can be installed per page, setting one even in another JavaScript world uninstalls any already installed web channel.
See also
webChannel()
ScriptWorldId
- PySide2.QtWebEngineWidgets.QWebEnginePage.setZoomFactor(factor)¶
- Parameters:
factor – float
This property holds The zoom factor for the page content..
Valid values are within the range from
0.25
to5.0
. The default factor is1.0
.
- PySide2.QtWebEngineWidgets.QWebEnginePage.settings()¶
- Return type:
Returns a pointer to the page’s settings object.
See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.title()¶
- Return type:
str
This property holds The title of the page as defined by the HTML
<title>
element..If the page has no
<title>
element, then the URL is used instead. Forfile://
URLs only the filename is used and not the full path.By default, before any content has been loaded, this property contains an empty string.
See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.titleChanged(title)¶
- Parameters:
title – str
- PySide2.QtWebEngineWidgets.QWebEnginePage.toHtml(arg__1)¶
- Parameters:
arg__1 – object
- PySide2.QtWebEngineWidgets.QWebEnginePage.toPlainText(arg__1)¶
- Parameters:
arg__1 – object
- PySide2.QtWebEngineWidgets.QWebEnginePage.triggerAction(action[, checked=false])¶
- Parameters:
action –
WebAction
checked – bool
This function can be called to trigger the specified
action
. It is also called by Qt WebEngine if the user triggers the action, for example through a context menu item.If
action
is a checkable action, thenchecked
specifies whether the action is toggled or not.See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.url()¶
- Return type:
This property holds The URL of the page currently viewed..
Setting this property clears the view and loads the URL.
By default, this property contains an empty, invalid URL.
See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.urlChanged(url)¶
- Parameters:
url –
PySide2.QtCore.QUrl
- PySide2.QtWebEngineWidgets.QWebEnginePage.view()¶
- Return type:
Returns the view widget that is associated with the web page.
See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.visibleChanged(visible)¶
- Parameters:
visible – bool
- PySide2.QtWebEngineWidgets.QWebEnginePage.webChannel()¶
- Return type:
Returns a pointer to the web channel instance used by this page or a null pointer if none was set. This channel automatically uses the internal web engine transport mechanism over Chromium IPC that is exposed in the JavaScript context of this page as
qt.webChannelTransport
.See also
- PySide2.QtWebEngineWidgets.QWebEnginePage.windowCloseRequested()¶
- PySide2.QtWebEngineWidgets.QWebEnginePage.zoomFactor()¶
- Return type:
float
This property holds The zoom factor for the page content..
Valid values are within the range from
0.25
to5.0
. The default factor is1.0
.
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.