QWebEnginePage — PyQt Documentation v5.15.7 (original) (raw)
PyQt5.QtWebEngineWidgets.QWebEnginePage
Inherits from QObject.
Description¶
The QWebEnginePage class provides an object to view and edit web documents.
A web engine page holds the contents of an HTML document, the history of navigated links, and actions.
QWebEnginePage’s API is very similar to QWebEngineView, as you are still provided with common functions like action() (known as pageAction() in QWebEngineView), triggerAction(), and findText().
A page can be loaded using load() or setUrl(). Alternatively, if you have the HTML content readily available, you can use setHtml(). 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 (see url()) as well as the URL originally requested to be loaded (see requestedUrl()). These methods make possible the retrieval of the URL before and after a DNS resolution or a redirection occurs during the load process. The requestedUrl() 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 the icon() or its URL using the iconUrl() property. If the title or the icon changes, the corresponding titleChanged, iconChanged and iconUrlChanged signals will be emitted. The zoomFactor() 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 the loadProgress signal is emitted whenever an element of the web page completes loading, such as an embedded image or a script. The loadFinished signal is emitted when the page contents have been loaded completely, independent of script execution or page rendering. Its argument, either true
or false
, 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
and http://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 of http://www.example.com/
, because they are of a different security origin. By default, local schemes like file://
and qrc://
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 that file://
will not be able to access http://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 the runJavaScript()
version without the world ID is the same as running the script in the MainWorld
.
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).
Classes¶
Enums¶
Feature
TODO
Member | Value | Description |
---|---|---|
DesktopAudioVideoCapture | TODO | TODO |
DesktopVideoCapture | TODO | TODO |
Geolocation | TODO | TODO |
MediaAudioCapture | TODO | TODO |
MediaAudioVideoCapture | TODO | TODO |
MediaVideoCapture | TODO | TODO |
MouseLock | TODO | TODO |
Notifications | TODO | TODO |
FileSelectionMode
TODO
Member | Value | Description |
---|---|---|
FileSelectOpen | TODO | TODO |
FileSelectOpenMultiple | TODO | TODO |
FindFlag
TODO
Member | Value | Description |
---|---|---|
FindBackward | TODO | TODO |
FindCaseSensitively | TODO | TODO |
JavaScriptConsoleMessageLevel
TODO
Member | Value | Description |
---|---|---|
ErrorMessageLevel | TODO | TODO |
InfoMessageLevel | TODO | TODO |
WarningMessageLevel | TODO | TODO |
LifecycleState
TODO
Member | Value | Description |
---|---|---|
Active | TODO | TODO |
Discarded | TODO | TODO |
Frozen | TODO | TODO |
NavigationType
TODO
Member | Value | Description |
---|---|---|
NavigationTypeBackForward | TODO | TODO |
NavigationTypeFormSubmitted | TODO | TODO |
NavigationTypeLinkClicked | TODO | TODO |
NavigationTypeOther | TODO | TODO |
NavigationTypeRedirect | TODO | TODO |
NavigationTypeReload | TODO | TODO |
NavigationTypeTyped | TODO | TODO |
PermissionPolicy
TODO
Member | Value | Description |
---|---|---|
PermissionDeniedByUser | TODO | TODO |
PermissionGrantedByUser | TODO | TODO |
PermissionUnknown | TODO | TODO |
RenderProcessTerminationStatus
TODO
Member | Value | Description |
---|---|---|
AbnormalTerminationStatus | TODO | TODO |
CrashedTerminationStatus | TODO | TODO |
KilledTerminationStatus | TODO | TODO |
NormalTerminationStatus | TODO | TODO |
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 by action().
Member | Value | Description |
---|---|---|
AlignCenter | 38 | Aligns the lines containing the selection or the cursor at the center. Requires contenteditable="true". (Added in Qt 5.10) |
AlignJustified | 40 | Stretches the lines containing the selection or the cursor so that each line has equal width. Requires contenteditable="true". (Added in Qt 5.10) |
AlignLeft | 37 | Aligns the lines containing the selection or the cursor to the left. Requires contenteditable="true". (Added in Qt 5.10) |
AlignRight | 39 | Aligns the lines containing the selection or the cursor to the right. Requires contenteditable="true". (Added in Qt 5.10) |
Back | 0 | Navigate back in the history of navigated links. |
Copy | 5 | Copy the content currently selected into the clipboard. |
CopyImageToClipboard | 17 | Copy the clicked image to the clipboard. (Added in Qt 5.6) |
CopyImageUrlToClipboard | 18 | Copy the clicked image’s URL to the clipboard. (Added in Qt 5.6) |
CopyLinkToClipboard | 15 | Copy the current link to the clipboard. (Added in Qt 5.6) |
CopyMediaUrlToClipboard | 20 | Copy the hovered audio or video’s URL to the clipboard. (Added in Qt 5.6) |
Cut | 4 | Cut the content currently selected into the clipboard. |
DownloadImageToDisk | 19 | Download the highlighted image to the disk. (Added in Qt 5.6) |
DownloadLinkToDisk | 16 | Download the current link to the disk. (Added in Qt 5.6) |
DownloadMediaToDisk | 25 | Download the hovered audio or video to the disk. (Added in Qt 5.6) |
ExitFullScreen | 27 | Exit the fullscreen mode. (Added in Qt 5.6) |
Forward | 1 | Navigate forward in the history of navigated links. |
Indent | 41 | Indents the lines containing the selection or the cursor. Requires contenteditable="true". (Added in Qt 5.10) |
InsertOrderedList | 43 | Inserts an ordered list at the current cursor position, deleting the current selection. Requires contenteditable="true". (Added in Qt 5.10) |
InsertUnorderedList | 44 | Inserts an unordered list at the current cursor position, deleting the current selection. Requires contenteditable="true". (Added in Qt 5.10) |
InspectElement | 26 | Trigger any attached Web Inspector to inspect the highlighed element. (Added in Qt 5.6) |
NoWebAction | - 1 | No action is triggered. |
OpenLinkInNewBackgroundTab | 31 | Open the current link in a new background tab. (Added in Qt 5.7) |
OpenLinkInNewTab | 14 | Open the current link in a new tab. (Added in Qt 5.6) |
OpenLinkInNewWindow | 13 | Open the current link in a new window. (Added in Qt 5.6) |
OpenLinkInThisWindow | 12 | Open the current link in the current window. (Added in Qt 5.6) |
Outdent | 42 | Outdents the lines containing the selection or the cursor. Requires contenteditable="true". (Added in Qt 5.10) |
Paste | 6 | Paste content from the clipboard. |
PasteAndMatchStyle | 11 | Paste content from the clipboard with current style. |
Redo | 8 | Redo the last editing action. |
Reload | 3 | Reload the current page. |
ReloadAndBypassCache | 10 | Reload the current page, but do not use any local cache. |
RequestClose | 28 | 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) |
SavePage | 30 | Save the current page to disk. MHTML is the default format that is used to store the web page on disk. (Added in Qt 5.7) |
SelectAll | 9 | Select all content. |
Stop | 2 | Stop loading the current page. |
ToggleBold | 33 | Toggles boldness for the selection or at the cursor position. Requires contenteditable="true". (Added in Qt 5.10) |
ToggleItalic | 34 | Toggles italics for the selection or at the cursor position. Requires contenteditable="true". (Added in Qt 5.10) |
ToggleMediaControls | 21 | Toggle between showing and hiding the controls for the hovered audio or video element. (Added in Qt 5.6) |
ToggleMediaLoop | 22 | Toggle whether the hovered audio or video should loop on completetion or not. (Added in Qt 5.6) |
ToggleMediaMute | 24 | Mute or unmute the hovered audio or video element. (Added in Qt 5.6) |
ToggleMediaPlayPause | 23 | Toggle the play/pause state of the hovered audio or video element. (Added in Qt 5.6) |
ToggleStrikethrough | 36 | Toggles striking through the selection or at the cursor position. Requires contenteditable="true". (Added in Qt 5.10) |
ToggleUnderline | 35 | Toggles underlining of the selection or at the cursor position. Requires contenteditable="true". (Added in Qt 5.10) |
Undo | 7 | Undo the last editing action. |
Unselect | 29 | Clear the current selection. (Added in Qt 5.7) |
ViewSource | 32 | Show the source of the current page in a new tab. (Added in Qt 5.8) |
WebWindowType
This enum describes the types of window that can be created by the createWindow() function:
Member | Value | Description |
---|---|---|
WebBrowserBackgroundTab | 3 | A web browser tab without hiding the current visible WebEngineView. (Added in Qt 5.7) |
WebBrowserTab | 1 | A web browser tab. |
WebBrowserWindow | 0 | A complete web browser window. |
WebDialog | 2 | A window without decoration. |
Methods¶
__init__(parent: QObject = None)
TODO
__init__(QWebEngineProfile, parent: QObject = None)
TODO
acceptNavigationRequest(QUrl, NavigationType, bool) → bool
TODO
TODO
backgroundColor() → QColor
See also
certificateError(QWebEngineCertificateError) → bool
TODO
chooseFiles(FileSelectionMode, Iterable[str], Iterable[str]) → List[str]
TODO
contentsSize() → QSizeF
TODO
TODO
createStandardContextMenu() → QMenu
TODO
createWindow(WebWindowType) → QWebEnginePage
TODO
devToolsPage() → QWebEnginePage
See also
download(QUrl, filename: str = '')
TODO
event(QEvent) → bool
TODO
findText(str, options: Union[FindFlags, FindFlag] = QWebEnginePage.FindFlags(), resultCallback: Callable[[bool], None] = 0)
TODO
hasSelection() → bool
TODO
history() → QWebEngineHistory
TODO
icon() → QIcon
TODO
iconUrl() → QUrl
TODO
inspectedPage() → QWebEnginePage
See also
isAudioMuted() → bool
TODO
isVisible() → bool
TODO
javaScriptAlert(QUrl, str)
TODO
javaScriptConfirm(QUrl, str) → bool
TODO
javaScriptConsoleMessage(JavaScriptConsoleMessageLevel, str, int, str)
TODO
javaScriptPrompt(QUrl, str, str) → (bool, str)
TODO
lifecycleState() → LifecycleState
TODO
load(QUrl)
TODO
load(QWebEngineHttpRequest)
TODO
print(QPrinter, Callable[[bool], None])
TODO
printToPdf(str, pageLayout: QPageLayout = QPageLayout(QPageSize(QPageSize.PageSizeId.A4),QPageLayout.Orientation.Portrait,QMarginsF()))
TODO
printToPdf(Callable[[Union[QByteArray, bytes, bytearray]], None], pageLayout: QPageLayout = QPageLayout(QPageSize(QPageSize.PageSizeId.A4),QPageLayout.Orientation.Portrait,QMarginsF()))
TODO
profile() → QWebEngineProfile
TODO
recentlyAudible() → bool
TODO
recommendedState() → LifecycleState
TODO
renderProcessPid() → int
TODO
replaceMisspelledWord(str)
TODO
requestedUrl() → QUrl
TODO
runJavaScript(str)
TODO
runJavaScript(str, int)
TODO
runJavaScript(str, Callable[[Any], None])
TODO
runJavaScript(str, int, callable)
TODO
save(str, format: SavePageFormat = MimeHtmlSaveFormat)
TODO
scripts() → QWebEngineScriptCollection
TODO
scrollPosition() → QPointF
TODO
selectedText() → str
TODO
setAudioMuted(bool)
setBackgroundColor(Union[QColor, GlobalColor])
See also
setContent(Union[QByteArray, bytes, bytearray], mimeType: str = '', baseUrl: QUrl = QUrl())
TODO
setDevToolsPage(QWebEnginePage)
setFeaturePermission(QUrl, Feature, PermissionPolicy)
TODO
setHtml(str, baseUrl: QUrl = QUrl())
TODO
setInspectedPage(QWebEnginePage)
See also
setLifecycleState(LifecycleState)
TODO
settings() → QWebEngineSettings
TODO
setUrl(QUrl)
setUrlRequestInterceptor(QWebEngineUrlRequestInterceptor)
TODO
setView(QWidget)
setVisible(bool)
TODO
setWebChannel(QWebChannel)
setWebChannel(QWebChannel, int)
TODO
setZoomFactor(float)
title() → str
TODO
toHtml(Callable[[str], None])
TODO
toPlainText(Callable[[str], None])
TODO
triggerAction(WebAction, checked: bool = False)
TODO
url() → QUrl
view() → QWidget
webChannel() → QWebChannel
See also
zoomFactor() → float
See also
Signals¶
audioMutedChanged(bool)
TODO
authenticationRequired(QUrl, QAuthenticator)
TODO
contentsSizeChanged(QSizeF)
TODO
featurePermissionRequestCanceled(QUrl, Feature)
TODO
featurePermissionRequested(QUrl, Feature)
TODO
findTextFinished(QWebEngineFindTextResult)
TODO
fullScreenRequested(QWebEngineFullScreenRequest)
TODO
geometryChangeRequested(QRect)
TODO
iconChanged(QIcon)
TODO
iconUrlChanged(QUrl)
TODO
lifecycleStateChanged(LifecycleState)
TODO
linkHovered(str)
TODO
loadFinished(bool)
TODO
loadProgress(int)
TODO
loadStarted()
TODO
pdfPrintingFinished(str, bool)
TODO
printRequested()
TODO
proxyAuthenticationRequired(QUrl, QAuthenticator, str)
TODO
quotaRequested(QWebEngineQuotaRequest)
TODO
recentlyAudibleChanged(bool)
TODO
recommendedStateChanged(LifecycleState)
TODO
registerProtocolHandlerRequested(QWebEngineRegisterProtocolHandlerRequest)
TODO
renderProcessPidChanged(int)
TODO
renderProcessTerminated(RenderProcessTerminationStatus, int)
TODO
scrollPositionChanged(Union[QPointF, QPoint])
TODO
selectClientCertificate(QWebEngineClientCertificateSelection)
TODO
selectionChanged()
TODO
titleChanged(str)
TODO
urlChanged(QUrl)
TODO
visibleChanged(bool)
TODO
windowCloseRequested()
TODO