QWebFrame Class Reference

[ QtWebKit module]

The QWebFrame class represents a frame in a web page. 更多...

继承 QObject .

类型

方法

Qt Signals


详细描述

The QWebFrame class represents a frame in a web page.

QWebFrame represents a frame inside a web page. Each 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 load () 或 setUrl (). Alternatively, if you have the HTML content readily available, you can use setHtml () 代替。

page () 函数返回 pointer to the web page object. See QWebView 元素 for an explanation of how web frames are related to a web page and web view.

The QWebFrame class also offers methods to retrieve both the URL currently loaded by the frame (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 frame history ( QWebHistory ) 若加载成功。

The title of an HTML frame can be accessed with the title () property. Additionally, a frame may also specify an icon, which can be accessed using the icon () property. If the title or the icon changes, the corresponding titleChanged () 和 iconChanged () signals will be emitted. The zoomFactor () property can be used to change the overall size of the content displayed in the frame.

QWebFrame objects are created and controlled by the web page. You can connect to the web page's frameCreated() signal to be notified when a new frame is created.

There are multiple ways to programmatically examine the contents of a frame. The hitTestContent () function can be used to find elements by coordinate. For access to the underlying DOM tree, there is documentElement (), findAllElements () 和 findFirstElement ().

A QWebFrame can be printed onto a QPrinter 使用 print_ () function. This function is marked as a slot and can be conveniently connected to QPrintPreviewDialog 's paintRequested() 信号。


类型文档编制

QWebFrame.RenderLayer

This enum describes the layers available for rendering using render() . The layers can be OR-ed together from the following list:

常量 描述
QWebFrame.ContentsLayer 0x10 The web content of the frame
QWebFrame.ScrollBarLayer 0x20 The scrollbars of the frame
QWebFrame.PanIconLayer 0x40 The icon used when panning the frame
QWebFrame.AllLayers 0xff Includes all the above layers

方法文档编制

QWebFrame.addToJavaScriptWindowObject ( self , QString  name , QObject   object )

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 javaScriptWindowObjectCleared () 信号。

If Javascript is not enabled for this page, then this method does nothing.

object will never be explicitly deleted by QtWebKit .

QUrl QWebFrame.baseUrl ( self )

list-of-QWebFrame QWebFrame.childFrames ( self )

Returns a list of all frames that are direct children of this frame.

另请参阅 parentFrame ().

QSize QWebFrame.contentsSize ( self )

QWebElement QWebFrame.documentElement ( self )

Returns the document element of this frame.

The document element provides access to the entire structured content of the frame.

该函数在 Qt 4.6 引入。

QVariant QWebFrame.evaluateJavaScript ( self , QString  scriptSource )

This method is also a Qt slot with the C++ signature QVariant evaluateJavaScript(const QString&) .

Evaluates the JavaScript defined by scriptSource 使用 this frame as context and returns the result of the last executed 语句。

另请参阅 addToJavaScriptWindowObject () and javaScriptWindowObjectCleared ().

bool QWebFrame.event ( self , QEvent )

重实现自 QObject.event ().

QWebElementCollection QWebFrame.findAllElements ( self , QString  selectorQuery )

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.

该函数在 Qt 4.6 引入。

另请参阅 QWebElement.findAll ().

QWebElement QWebFrame.findFirstElement ( self , QString  selectorQuery )

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.

该函数在 Qt 4.6 引入。

另请参阅 QWebElement.findFirst ().

QString QWebFrame.frameName ( self )

The name of this frame as defined by the parent frame.

QRect QWebFrame.geometry ( self )

Return the geometry of the frame relative to it's parent frame.

bool QWebFrame.hasFocus ( self )

QWebHitTestResult QWebFrame.hitTestContent ( self , QPoint   pos )

Performs a hit test on the frame contents at the given position pos and returns the hit test result.

QIcon QWebFrame.icon ( self )

QWebFrame.load ( self , QUrl   url )

加载 url into this frame.

注意: The view remains the same until enough data has arrived to display the new url .

另请参阅 setUrl (), setHtml (),和 setContent ().

QWebFrame.load ( self , QNetworkRequest   request , QNetworkAccessManager.Operation   operation  = QNetworkAccessManager.GetOperation, QByteArray   body  = QByteArray())

Loads a network request, req , into this frame, using the method specified in operation .

body is optional and is only used for POST operations.

注意: The view remains the same until enough data has arrived to display the new content.

另请参阅 setUrl ().

dict-of-QString-list-of-QString QWebFrame.metaData ( self )

Returns the meta data in this frame as a QMultiMap

The meta data consists of the name and content attributes 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 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.

该函数在 Qt 4.5 引入。

QWebPage QWebFrame.page ( self )

The web page that contains this frame.

另请参阅 pageChanged ().

QWebFrame QWebFrame.parentFrame ( self )

Returns the parent frame of this frame, or 0 if the frame is the web pages main frame.

This is equivalent to qobject_cast< QWebFrame *>(frame-> parent ()).

另请参阅 childFrames ().

QPoint QWebFrame.pos ( self )

Returns the position of the frame relative to it's parent frame.

QWebFrame.print_ ( self , QPrinter   printer )

This method is also a Qt slot with the C++ signature void print(QPrinter*) const .

Prints the frame to the given printer .

另请参阅 render ().

QWebFrame.render ( self , QPainter   painter , QRegion   clip )

Render the frame into painter .

QWebFrame.render ( self , QPainter   painter )

Render the frame into painter clipping to clip .

QWebFrame.render ( self , QPainter , RenderLayer   layer , QRegion   clip  = QRegion())

渲染 layer of the frame using painter clipping to clip .

该函数在 Qt 4.6 引入。

另请参阅 print_ ().

QString QWebFrame.renderTreeDump ( self )

Returns a dump of the rendering tree. This is mainly useful for debugging html.

QUrl QWebFrame.requestedUrl ( self )

QWebFrame.scroll ( self , int, int)

Scrolls the frame dx 像素到右侧和 dy pixels downward. Both dx and dy 可能为负值。

该函数在 Qt 4.5 引入。

另请参阅 QWebFrame.scrollPosition .

QRect QWebFrame.scrollBarGeometry ( self , Qt.Orientation   orientation )

Returns the geometry for the scrollbar with orientation orientation .

If the scrollbar does not exist an empty rect is returned.

该函数在 Qt 4.6 引入。

int QWebFrame.scrollBarMaximum ( self , Qt.Orientation   orientation )

Returns the maximum value for the scrollbar with orientation orientation , or 0 if no scrollbar is found for orientation .

另请参阅 scrollBarMinimum ().

int QWebFrame.scrollBarMinimum ( self , Qt.Orientation   orientation )

Returns the minimum value for the scrollbar with orientation orientation .

The minimum value is always 0.

另请参阅 scrollBarMaximum ().

Qt.ScrollBarPolicy QWebFrame.scrollBarPolicy ( self , Qt.Orientation   orientation )

Returns the scrollbar policy for the scrollbar defined by orientation .

另请参阅 setScrollBarPolicy ().

int QWebFrame.scrollBarValue ( self , Qt.Orientation   orientation )

Returns the current value for the scrollbar with orientation orientation , or 0 if no scrollbar is found for orientation .

另请参阅 setScrollBarValue (), scrollBarMinimum (), and scrollBarMaximum ().

QPoint QWebFrame.scrollPosition ( self )

QWebFrame.scrollToAnchor ( self , QString  anchor )

Scrolls the frame to the given anchor name.

该函数在 Qt 4.7 引入。

QWebSecurityOrigin QWebFrame.securityOrigin ( self )

Returns the frame's security origin.

该函数在 Qt 4.5 引入。

QWebFrame.setContent ( self , QByteArray   data , QString  mimeType  = QString(), QUrl   baseUrl  = QUrl())

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.

External objects referenced in the content are located relative to baseUrl .

data is loaded immediately; external objects are loaded asynchronously.

注意: This method will not affect session or global history for the frame.

另请参阅 toHtml () 和 setHtml ().

QWebFrame.setFocus ( self )

Gives keyboard input focus to this frame.

该函数在 Qt 4.6 引入。

另请参阅 hasFocus ().

QWebFrame.setHtml ( self , QString  html , QUrl   baseUrl  = QUrl())

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 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 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", 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) setContent () should be used 代替。

另请参阅 toHtml (), setContent (),和 load ().

QWebFrame.setScrollBarPolicy ( self , Qt.Orientation   orientation , Qt.ScrollBarPolicy   policy )

Sets the scrollbar policy for the scrollbar defined by orientation to policy .

另请参阅 scrollBarPolicy ().

QWebFrame.setScrollBarValue ( self , Qt.Orientation   orientation , int  value )

设置当前 value for the scrollbar with orientation orientation .

The scrollbar forces the value to be within the legal range: minimum <= value <= maximum.

Changing the value also updates the thumb position.

另请参阅 scrollBarValue (), scrollBarMinimum (),和 scrollBarMaximum ().

QWebFrame.setScrollPosition ( self , QPoint   pos )

QWebFrame.setTextSizeMultiplier ( self , float  factor )

Sets the value of the multiplier used to scale the text in a Web frame to the factor 指定。

另请参阅 textSizeMultiplier ().

QWebFrame.setUrl ( self , QUrl   url )

QWebFrame.setZoomFactor ( self , float  factor )

float QWebFrame.textSizeMultiplier ( self )

Returns the value of the multiplier used to scale the text in a Web frame.

另请参阅 setTextSizeMultiplier ().

QString QWebFrame.title ( self )

QString QWebFrame.toHtml ( self )

Returns the frame's content as HTML, enclosed in HTML and BODY 标签。

另请参阅 setHtml () and toPlainText ().

QString QWebFrame.toPlainText ( self )

Returns the content of this frame converted to plain text, completely stripped of all HTML formatting.

另请参阅 toHtml ().

QUrl QWebFrame.url ( self )

float QWebFrame.zoomFactor ( self )


Qt Signal Documentation

void contentsSizeChanged (const QSize&)

This is the default overload of this signal.

This signal is emitted when the frame's contents size changes to size .

该函数在 Qt 4.6 引入。

另请参阅 contentsSize ().

void iconChanged ()

This is the default overload of this signal.

This signal is emitted when the icon ("favicon") associated with the frame has been loaded.

另请参阅 icon ().

void initialLayoutCompleted ()

This is the default overload of this signal.

This signal is emitted when the frame is laid out the first time. This is the first time you will see contents displayed on the frame.

注意: A frame can be laid out multiple times.

void javaScriptWindowObjectCleared ()

This is the default overload of this signal.

This signal is emitted whenever the global window object of the JavaScript environment is cleared, e.g., before starting a new load.

If you intend to add QObjects QWebFrame 使用 addToJavaScriptWindowObject (), you should add them in a slot connected to this signal. This ensures that your objects remain accessible when loading new URLs.

void loadFinished (bool)

This is the default overload of this signal.

This signal is emitted when a load of this frame is finished. ok will indicate whether the load was successful or any error occurred.

该函数在 Qt 4.6 引入。

另请参阅 loadStarted ().

void loadStarted ()

This is the default overload of this signal.

This signal is emitted when a new load of this frame is started.

该函数在 Qt 4.6 引入。

另请参阅 loadFinished ().

void pageChanged ()

This is the default overload of this signal.

This signal is emitted when this frame has been moved to a different QWebPage .

该函数在 Qt 4.7 引入。

另请参阅 page ().

void titleChanged (const QString&)

This is the default overload of this signal.

This signal is emitted whenever the title of the frame changes. title 字符串指定新标题。

另请参阅 title ().

void urlChanged (const QUrl&)

This is the default overload of this signal.

This signal is emitted with the URL of the frame when the frame's title is received. The new URL is specified by url .

另请参阅 url ().