PySide.QtWebKit.QWebFrame class represents a frame in a web page.
PySide.QtWebKit.QWebFrame represents a frame inside a web page. Each PySide.QtWebKit.QWebPage object contains at least one frame, the main frame, obtained using QWebPage.mainFrame() . Additional frames will be created for HTML <frame> or <iframe> 元素。
A frame can be loaded using PySide.QtWebKit.QWebFrame.load() or PySide.QtWebKit.QWebFrame.setUrl() . Alternatively, if you have the HTML content readily available, you can use PySide.QtWebKit.QWebFrame.setHtml() 代替。
PySide.QtWebKit.QWebFrame.page() function returns a pointer to the web page object. See Elements of QWebView for an explanation of how web frames are related to a web page and web view.
PySide.QtWebKit.QWebFrame class also offers methods to retrieve both the URL currently loaded by the frame (see PySide.QtWebKit.QWebFrame.url() ) as well as the URL originally requested to be loaded (see PySide.QtWebKit.QWebFrame.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 PySide.QtWebKit.QWebFrame.requestedUrl() also matches to the URL added to the frame history ( PySide.QtWebKit.QWebHistory ) 若加载成功。
The title of an HTML frame can be accessed with the PySide.QtWebKit.QWebFrame.title() property. Additionally, a frame may also specify an icon, which can be accessed using the PySide.QtWebKit.QWebFrame.icon() property. If the title or the icon changes, the corresponding PySide.QtWebKit.QWebFrame.titleChanged() and PySide.QtWebKit.QWebFrame.iconChanged() signals will be emitted. The PySide.QtWebKit.QWebFrame.zoomFactor() property can be used to change the overall size of the content displayed in the frame.
PySide.QtWebKit.QWebFrame objects are created and controlled by the web page. You can connect to the web page's PySide.QtWebKit.QWebPage.frameCreated() signal to be notified when a new frame is created.
There are multiple ways to programmatically examine the contents of a frame. The PySide.QtWebKit.QWebFrame.hitTestContent() function can be used to find elements by coordinate. For access to the underlying DOM tree, there is PySide.QtWebKit.QWebFrame.documentElement() , PySide.QtWebKit.QWebFrame.findAllElements() and PySide.QtWebKit.QWebFrame.findFirstElement() .
A PySide.QtWebKit.QWebFrame can be printed onto a PySide.QtGui.QPrinter 使用 print() function. This function is marked as a slot and can be conveniently connected to PySide.QtGui.QPrintPreviewDialog ‘s PySide.QtGui.QPrintPreviewDialog.paintRequested() 信号。
This enum describes the layers available for rendering using PySide.QtWebKit.QWebFrame.render() . The layers can be OR-ed together from the following list:
| 常量 | 描述 |
|---|---|
| QWebFrame.ContentsLayer | The web content of the frame |
| QWebFrame.ScrollBarLayer | The scrollbars of the frame |
| QWebFrame.PanIconLayer | The icon used when panning the frame |
| QWebFrame.AllLayers | Includes all the above layers |
注意
该枚举在 Qt 4.6 引入或被修改
| 参数: |
|
|---|
Make object available under name from within the frame's JavaScript context. The object will be inserted as a child of the frame's window object.
Qt properties will be exposed as JavaScript properties and slots as JavaScript methods. The interaction between C++ and JavaScript is explained in the documentation of the QtWebKit bridge .
If you want to ensure that your QObjects remain accessible after loading a new URL, you should add them in a slot connected to the PySide.QtWebKit.QWebFrame.javaScriptWindowObjectCleared() 信号。
If Javascript is not enabled for this page, then this method does nothing.
object will never be explicitly deleted by QtWebKit .
| 参数: |
|
|---|
| 返回类型: | PySide.QtCore.QUrl |
|---|
This property holds the base URL of the frame, can be used to resolve relative URLs.
| 返回类型: |
|---|
Returns a list of all frames that are direct children of this frame.
| 返回类型: | PySide.QtCore.QSize |
|---|
This property holds the size of the contents in this frame.
| 参数: | size – PySide.QtCore.QSize |
|---|
| 返回类型: | PySide.QtWebKit.QWebElement |
|---|
Returns the document element of this frame.
The document element provides access to the entire structured content of the frame.
| 参数: | scriptSource – unicode |
|---|---|
| 返回类型: | object |
Evaluates the JavaScript defined by scriptSource using this frame as context and returns the result of the last executed statement.
| 参数: | selectorQuery – unicode |
|---|---|
| 返回类型: | PySide.QtWebKit.QWebElementCollection |
Returns a new list of elements matching the given CSS selector selectorQuery . If there are no matching elements, an empty list is returned.
Standard CSS2 selector syntax is used for the query.
| 参数: | selectorQuery – unicode |
|---|---|
| 返回类型: | PySide.QtWebKit.QWebElement |
Returns the first element in the frame's document that matches the given CSS selector selectorQuery . If there is no matching element, a null element is returned.
Standard CSS2 selector syntax is used for the query.
| 返回类型: | unicode |
|---|
The name of this frame as defined by the parent frame.
| 返回类型: | PySide.QtCore.QRect |
|---|
Return the geometry of the frame relative to it's parent frame.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if this frame has keyboard input focus; otherwise, returns false.
| 参数: | pos – PySide.QtCore.QPoint |
|---|---|
| 返回类型: | PySide.QtWebKit.QWebHitTestResult |
Performs a hit test on the frame contents at the given position pos and returns the hit test result.
| 返回类型: | PySide.QtGui.QIcon |
|---|
This property holds the icon associated with this frame.
| 参数: | url – PySide.QtCore.QUrl |
|---|
加载 url into this frame.
注意
The view remains the same until enough data has arrived to display the new url .
| 参数: |
|
|---|
| 参数: | ok – PySide.QtCore.bool |
|---|
| 返回类型: | PyObject |
|---|
Returns the meta data in this frame as a QMultiMap
The meta data consists of the name and content attributes of the of the <meta> tags in the HTML document.
例如:
<html>
<head>
<meta name="description" content="This document is a tutorial about Qt development">
<meta name="keywords" content="Qt, WebKit, Programming">
</head>
...
</html>
Given the above HTML code the PySide.QtWebKit.QWebFrame.metaData() function will return a map with two entries:
| Key | 值 |
| “description” | “This document is a tutorial about Qt development” |
| “keywords” | “Qt, WebKit , Programming” |
This function returns a multi map to support multiple meta tags with the same attribute name.
| 返回类型: | PySide.QtWebKit.QWebPage |
|---|
The web page that contains this frame.
| 返回类型: | PySide.QtWebKit.QWebFrame |
|---|
Returns the parent frame of this frame, or 0 if the frame is the web pages main frame.
This is equivalent to qobject_cast< PySide.QtWebKit.QWebFrame *>(frame-> PySide.QtCore.QObject.parent() ).
| 返回类型: | PySide.QtCore.QPoint |
|---|
Returns the position of the frame relative to it's parent frame.
| 参数: | printer – PySide.QtGui.QPrinter |
|---|
Prints the frame to the given printer .
| 参数: |
|
|---|
渲染 layer of the frame using painter clipping to clip .
另请参阅
print()
| 参数: |
|
|---|
Render the frame into painter clipping to clip .
| 参数: | arg__1 – PySide.QtGui.QPainter |
|---|
Render the frame into painter .
| 返回类型: | unicode |
|---|
Returns a dump of the rendering tree. This is mainly useful for debugging html.
| 返回类型: | PySide.QtCore.QUrl |
|---|
The URL requested to loaded by the frame currently viewed. The URL may differ from the one returned by PySide.QtWebKit.QWebFrame.url() if a DNS resolution or a redirection occurs.
| 参数: |
|
|---|
Scrolls the frame dx 像素到右侧和 dy pixels downward. Both dx and dy 可能为负值。
| 参数: | orientation – PySide.QtCore.Qt.Orientation |
|---|---|
| 返回类型: | PySide.QtCore.QRect |
| 参数: | orientation – PySide.QtCore.Qt.Orientation |
|---|---|
| 返回类型: | PySide.QtCore.int |
| 参数: | orientation – PySide.QtCore.Qt.Orientation |
|---|---|
| 返回类型: | PySide.QtCore.int |
| 参数: | orientation – PySide.QtCore.Qt.Orientation |
|---|---|
| 返回类型: | PySide.QtCore.Qt.ScrollBarPolicy |
| 参数: | orientation – PySide.QtCore.Qt.Orientation |
|---|---|
| 返回类型: | PySide.QtCore.int |
| 返回类型: | PySide.QtCore.QPoint |
|---|
This property holds the position the frame is currently scrolled to..
| 参数: | anchor – unicode |
|---|
Scrolls the frame to the given anchor name.
| 返回类型: | PySide.QtWebKit.QWebSecurityOrigin |
|---|
Returns the frame's security origin.
| 参数: |
|
|---|
Sets the content of this frame to the specified content data 。若 mimeType argument is empty it is currently assumed that the content is HTML but in future versions we may introduce auto-detection.
内容中引用的外部对象的定位相对于 baseUrl .
data 被立即加载;外部对象是异步加载的。
注意
This method will not affect session or global history for the frame.
Gives keyboard input focus to this frame.
| 参数: |
|
|---|
Sets the content of this frame to html . baseUrl is optional and used to resolve relative URLs in the document, such as referenced images or stylesheets.
html 被立即加载;外部对象是异步加载的。
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 subsequent html will be 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. It is also possible for the encoding to be specified by web server.
This is a convenience function equivalent to setContent(html, “text/html”, PySide.QtWebKit.QWebFrame.baseUrl() ).
注意
This method will not affect session or global history for the frame.
警告
This function works only for HTML, for other mime types (i.e. XHTML, SVG) PySide.QtWebKit.QWebFrame.setContent() should be used instead.
| 参数: |
|
|---|
| 参数: |
|
|---|
| 参数: | pos – PySide.QtCore.QPoint |
|---|
This property holds the position the frame is currently scrolled to..
| 参数: | 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 .
注意
Setting this property also enables the ZoomTextOnly attribute in PySide.QtWebKit.QWebSettings .
| 参数: | url – PySide.QtCore.QUrl |
|---|
This property holds the url of the frame currently viewed.
设置此特性清零视图并加载 URL。
默认情况下,此特性包含空的无效 URL。
| 参数: | factor – PySide.QtCore.qreal |
|---|
This property holds the zoom factor for the frame.
| 返回类型: | 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 .
注意
Setting this property also enables the ZoomTextOnly attribute in PySide.QtWebKit.QWebSettings .
| 返回类型: | unicode |
|---|
This property holds the title of the frame as defined by the HTML <title> element.
| 参数: | title – unicode |
|---|
| 返回类型: | unicode |
|---|
Returns the frame's content as HTML, enclosed in HTML and BODY tags.
| 返回类型: | unicode |
|---|
Returns the content of this frame converted to plain text, completely stripped of all HTML formatting.
| 返回类型: | PySide.QtCore.QUrl |
|---|
This property holds the url of the frame currently viewed.
设置此特性清零视图并加载 URL。
默认情况下,此特性包含空的无效 URL。
| 参数: | url – PySide.QtCore.QUrl |
|---|
| 返回类型: | PySide.QtCore.qreal |
|---|
This property holds the zoom factor for the frame.