PySide6.QtWebEngineWidgets.QWebEngineView¶
- class QWebEngineView¶
- The - QWebEngineViewclass provides a widget that is used to view and edit web documents. More…- Synopsis¶- Properties¶- hasSelectionᅟ- Whether this page contains selected content or not
- iconᅟ- Associated with the page currently viewed
- iconUrlᅟ- URL of the icon associated with the page currently viewed
- selectedTextᅟ- Text currently selected
- titleᅟ- Of the page as defined by the HTML <title> element
- urlᅟ- URL of the web page currently viewed
- zoomFactorᅟ- Zoom factor for the view
 - Methods¶- def - __init__()
- def - findText()
- def - hasSelection()
- def - history()
- def - icon()
- def - iconUrl()
- def - load()
- def - page()
- def - pageAction()
- def - print()
- def - printToPdf()
- def - selectedText()
- def - setContent()
- def - setHtml()
- def - setPage()
- def - setUrl()
- def - setZoomFactor()
- def - settings()
- def - title()
- def - url()
- def - zoomFactor()
 - Virtual methods¶- def - createWindow()
 - Slots¶- Signals¶- def - iconChanged()
- def - iconUrlChanged()
- def - loadFinished()
- def - loadProgress()
- def - loadStarted()
- def - printFinished()
- def - printRequested()
- def - titleChanged()
- def - urlChanged()
 - Static functions¶- def - forPage()
 - 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 - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - A web view is the main widget component of the Qt WebEngine web browsing module. It can be used in various applications to display web content live from the Internet. - A web site can be loaded to a web view with the - load()function. The GET method is always used to load URLs.- Like all Qt widgets, the show() function must be invoked in order to display the web view. The snippet below illustrates this: - view = QWebEngineView() view.load(QUrl("https://qt-project.org/")) view.resize(1024, 750) view.show() - Alternatively, - setUrl()can be used to load a web site. If you have the HTML content readily available, you can use- setHtml()instead.- The - loadStarted()signal is emitted when the view begins loading and the- loadProgress()signal is emitted whenever an element of the web view completes loading, such as an embedded image or a script. The- loadFinished()signal is emitted when the view has been loaded completely. Its argument, either- trueor- false, indicates whether loading was successful or failed.- The - page()function returns a pointer to a web page object. A- QWebEngineViewcontains a- QWebEnginePage, which in turn allows access to the- QWebEngineHistoryin the page’s context.- The title of an HTML document can be accessed with the - title()property. Additionally, a web site may 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 widget features a context menu that is tailored to the element at hand, and includes actions useful in a browser. For a custom context menu, or for embedding actions in a menu or toolbar, the individual actions are available via - pageAction(). The web view maintains the state of the returned actions, but allows modification of action properties such as text or icon. The action semantics can also be triggered directly through- triggerPageAction().- 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 - QWebEngineViewand reimplement the- createWindow()function.- See also - WebEngine Widgets Simple Browser Example WebEngine Content Manipulation Example - Note - Properties can be used directly when - from __feature__ import true_propertyis used or via accessor functions otherwise.- property hasSelectionᅟ: bool¶
 - This property holds Whether this page contains selected content or not.. - By default, this property is - false.- See also - Access functions:
 - This property holds The icon associated with the page currently viewed.. - By default, this property contains a null icon. - See also - Access functions:
- Signal - iconChanged()
 
 - This property holds The URL of the icon associated with the page currently viewed.. - By default, this property contains an empty URL. - See also - Access functions:
- Signal - iconUrlChanged()
 
 - property selectedTextᅟ: str¶
 - This property holds The text currently selected.. - By default, this property contains an empty string. - See also - Access functions:
 - property titleᅟ: str¶
 - This property holds The title of the page as defined by the HTML - <title>element..- Equivalent to - title().- See also - Access functions:
 - 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. - See also - property zoomFactorᅟ: float¶
 - This property holds The zoom factor for the view.. - Valid values are within the range from - 0.25to- 5.0. The default factor is- 1.0.- Access functions:
 - Constructs an empty web view with the parent - parent.- See also - __init__(page[, parent=None])
- Parameters:
- page – - QWebEnginePage
- parent – - QWidget
 
 
 - Constructs a web view containing - pagewith the parent- parent.- Note - Ownership of - pageis not taken, and it is up to the caller to ensure it is deleted.- __init__(profile[, parent=None])
- Parameters:
- profile – - QWebEngineProfile
- parent – - QWidget
 
 
 - Constructs an empty web view using - profilewith the parent- parent.- back()¶
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - 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().triggerAction(QWebEnginePage.Back) - See also - Creates a standard context menu and returns a pointer to it. - createWindow(type)¶
- Parameters:
- type – - WebWindowType
- Return type:
 
 - This function is called from the - createWindow()method of the associated- QWebEnginePageeach time the page wants to create a new window of the given- type. For example, when a JavaScript request to open a document in a new window is issued.- Note - If the - createWindow()method of the associated page is reimplemented, this method is not called, unless explicitly done so in the reimplementation.- See also - findText(subString, options, resultCallback)
- Parameters:
- subString – str 
- options – Combination of - FindFlag
- resultCallback – - PyCallable
 
 
 - static forPage(page)¶
- Parameters:
- page – - QWebEnginePage
- Return type:
 
 - Returns the view if any, associated with the - page.- forward()¶
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - 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().triggerAction(QWebEnginePage.Forward) - See also - hasSelection()¶
- Return type:
- bool 
 
 - Getter of property - hasSelectionᅟ.- history()¶
- Return type:
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Returns a pointer to the view’s history of navigated web pages. - It is equivalent to: - view.page().history() - Getter of property - iconᅟ.- This signal is emitted when the icon (“favicon”) associated with the view is changed. The new icon is specified by - icon.- See also - Notification signal of property - iconᅟ.- Getter of property - iconUrlᅟ.- This signal is emitted when the URL of the icon (“favicon”) associated with the view is changed. The new URL is specified by - url.- See also - Notification signal of property - iconUrlᅟ.- lastContextMenuRequest()¶
- Return type:
 
 - Returns additional data about the current context menu. It is only guaranteed to be valid during the call to the - contextMenuEvent().- See also - Loads the specified - urland displays it.- Note - The view remains the same until enough data has arrived to display the new URL. - See also - load(request)
- Parameters:
- request – - QWebEngineHttpRequest
 
 - Issues the specified - requestand loads the response.- See also - loadFinished(ok)¶
- Parameters:
- ok – bool 
 
 - This signal is emitted when a load of the page has finished. - okwill indicate whether the load was successful or an error occurred.- See also - loadProgress(progress)¶
- Parameters:
- progress – int 
 
 - This signal is emitted every time an element in the web view completes loading, such as an embedded image or a script. Therefore, it tracks the collective progress of loading the web view. - The current value is provided by - progressand scales from 0 to 100, which is the default range of QProgressBar.- See also - loadStarted()¶
 - This signal is emitted when a new load of the page is started. - See also - page()¶
- Return type:
 
 - Returns a pointer to the underlying web page. - See also - Returns a pointer to a QAction that encapsulates the specified web action - action. This function will also set a default styled icon to the QAction if it lacks one.- pdfPrintingFinished(filePath, success)¶
- Parameters:
- filePath – str 
- success – bool 
 
 
 - This signal is emitted when printing the web page into a PDF file has finished. - filePathwill contain the path the file was requested to be created at, and- successwill be- trueif the file was successfully created and- falseotherwise.- See also - Renders the current content of the page into a temporary PDF document, then prints it using - printer.- The settings for creating and printing the PDF document will be retrieved from the - printerobject.- When finished the signal - printFinished()is emitted with the- truefor success or- falsefor failure.- It is the users responsibility to ensure the - printerremains valid until- printFinished()has been emitted.- Note - Printing runs on the browser process, which is by default not sandboxed. - Note - The data generation step of printing can be interrupted for a short period of time using the - Stopweb action.- Note - This function rasterizes the result when rendering onto - printer. Please consider raising the default resolution of- printerto at least 300 DPI or using- printToPdf()to produce PDF file output more effectively.- printFinished(success)¶
- Parameters:
- success – bool 
 
 - This signal is emitted when printing requested with - print()has finished. The parameter- successis- truefor success or- falsefor failure.- See also - printRequested()¶
 - This signal is emitted when the JavaScript - window.print()method is called or the user pressed the print button of PDF viewer plugin. Typically, the signal handler can simply call- print().- Since 6.8, this signal is only emitted for the main frame, instead of being emitted for any frame that requests printing. - See also - printRequestedByFrame(frame)¶
- Parameters:
- frame – - QWebEngineFrame
 
 - This signal is emitted when the JavaScript - window.print()method is called on- frame. If the frame is the main frame,- printRequestedis emitted instead.- See also - printToPdf(filePath[, layout=QPageLayout(QPageSize(QPageSize.A4), QPageLayout.Portrait, QMarginsF())[, ranges={}]])¶
- Parameters:
- filePath – str 
- layout – - QPageLayout
- ranges – - QPageRanges
 
 
 - Renders the current content of the page into a PDF document and saves it in the location specified in - filePath. The page size and orientation of the produced PDF document are taken from the values specified in- layout, while the range of pages printed is taken from- rangeswith the default being printing all pages.- This method issues an asynchronous request for printing the web page into a PDF and returns immediately. To be informed about the result of the request, connect to the signal - pdfPrintingFinished().- If a file already exists at the provided file path, it will be overwritten. - See also - reload()¶
 - Reloads the current document. - See also - renderProcessTerminated(terminationStatus, exitCode)¶
- Parameters:
- terminationStatus – - RenderProcessTerminationStatus
- exitCode – int 
 
 
 - This signal is emitted when the render process is terminated with a non-zero exit status. - terminationStatusis the termination status of the process and- exitCodeis the status code with which the process terminated.- selectedText()¶
- Return type:
- str 
 
 - Getter of property - selectedTextᅟ.- selectionChanged()¶
 - This signal is emitted whenever the selection changes. - Note - When using the mouse to select text by left-clicking and dragging, the signal will be emitted for each new character selected, and not upon releasing the left mouse button. - See also - setContent(data[, mimeType=""[, baseUrl=QUrl()]])¶
- Parameters:
- data – - QByteArray
- mimeType – str 
- baseUrl – - QUrl
 
 
 - Sets the content of the web view to - data. If the- mimeTypeargument is empty, it is assumed that the content is- text/plain,charset=US-ASCII.- External objects referenced in the content are located relative to - baseUrl. For external objects with relative URLs to be loaded,- baseUrlcannot be empty.- The data is loaded immediately; external objects are loaded asynchronously. - Sets the content of the web view to the specified - htmlcontent.- baseUrlis optional and used to resolve relative URLs in the document, such as referenced images or stylesheets. For example, if- htmlis 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.- The HTML document is loaded immediately, whereas external objects are loaded asynchronously. - When using this method, Qt WebEngine 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 - charsetattribute of the HTML script tag. Alternatively, the encoding can be specified by the web server.- This is a convenience function equivalent to - setContent(html, "text/html;charset=UTF-8", baseUrl).- Warning - This function works only for HTML. For other MIME types (such as XHTML or SVG), - setContent()should be used instead.- Note - Content larger than 2 MB cannot be displayed, because setHtml() converts the provided HTML to percent-encoding and places - data: in front of it to create the URL that it navigates to. Thereby, the provided code becomes a URL that exceeds the 2 MB limit set by Chromium. If the content is too large, the- loadFinished()signal is triggered with- success=false.- See also - setPage(page)¶
- Parameters:
- page – - QWebEnginePage
 
 - Makes - pagethe new web page of the web view.- The parent 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. - See also - Setter of property - urlᅟ.- setZoomFactor(factor)¶
- Parameters:
- factor – float 
 - See also 
 - Setter of property - zoomFactorᅟ.- settings()¶
- Return type:
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Returns a pointer to the view or page specific settings object. - It is equivalent to: - view.page().settings() - stop()¶
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Convenience slot that stops loading the document. - It is equivalent to: - view.page().triggerAction(QWebEnginePage.Stop) - See also - title()¶
- Return type:
- str 
 
 - Getter of property - titleᅟ.- titleChanged(title)¶
- Parameters:
- title – str 
 
 - This signal is emitted whenever the - titleof the view changes.- See also - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Triggers the specified - action. If it is a checkable action, the specified- checkedstate is assumed.- The following example triggers the copy action and therefore copies any selected text to the clipboard. - view.triggerPageAction(QWebEnginePage.Copy) - See also - Getter of property - urlᅟ.- This signal is emitted when the - urlof the view changes.- zoomFactor()¶
- Return type:
- float 
 - See also 
 - Getter of property - zoomFactorᅟ.