The QWebFrame class represents a frame in a web page. 更多...
| 頭: | #include <QWebFrame> |
| Since: | Qt 4.4 |
| 繼承: | QObject |
| enum | RenderLayer { ContentsLayer, ScrollBarLayer, PanIconLayer, AllLayers } |
|
|
| void | addToJavaScriptWindowObject (const QString & name , QObject * object ) |
| void | addToJavaScriptWindowObject (const QString & name , QObject * object , QScriptEngine::ValueOwnership own ) |
| QUrl | baseUrl () const |
| QList<QWebFrame *> | childFrames () const |
| QSize | contentsSize () const |
| QWebElement | documentElement () const |
| QWebElementCollection | findAllElements (const QString & selectorQuery ) const |
| QWebElement | findFirstElement (const QString & selectorQuery ) const |
| QString | frameName () const |
| QRect | geometry () const |
| bool | hasFocus () const |
| QWebHitTestResult | hitTestContent (const QPoint & pos ) const |
| QIcon | icon () const |
| void | load (const QUrl & url ) |
| void | load (const QNetworkRequest & req , QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, const QByteArray & body = QByteArray()) |
| QMultiMap<QString, QString> | metaData () const |
| QWebPage * | page () const |
| QWebFrame * | parentFrame () const |
| QPoint | pos () const |
| void | render (QPainter * painter ) |
| void | render (QPainter * painter , const QRegion & clip ) |
| void | render (QPainter * painter , RenderLayer layer , const QRegion & clip = QRegion()) |
| QString | renderTreeDump () const |
| QUrl | requestedUrl () const |
| void | scroll (int dx , int dy ) |
| QRect | scrollBarGeometry (Qt::Orientation orientation ) const |
| int | scrollBarMaximum (Qt::Orientation orientation ) const |
| int | scrollBarMinimum (Qt::Orientation orientation ) const |
| Qt::ScrollBarPolicy | scrollBarPolicy (Qt::Orientation orientation ) const |
| int | scrollBarValue (Qt::Orientation orientation ) const |
| QPoint | scrollPosition () const |
| void | scrollToAnchor (const QString & anchor ) |
| QWebSecurityOrigin | securityOrigin () const |
| void | setContent (const QByteArray & data , const QString & mimeType = QString(), const QUrl & baseUrl = QUrl()) |
| void | setFocus () |
| void | setHtml (const QString & html , const QUrl & baseUrl = QUrl()) |
| void | setScrollBarPolicy (Qt::Orientation orientation , Qt::ScrollBarPolicy policy ) |
| void | setScrollBarValue (Qt::Orientation orientation , int value ) |
| void | setScrollPosition (const QPoint & pos ) |
| void | setTextSizeMultiplier (qreal factor ) |
| void | setUrl (const QUrl & url ) |
| void | setZoomFactor (qreal factor ) |
| qreal | textSizeMultiplier () const |
| QString | title () const |
| QString | toHtml () const |
| QString | toPlainText () const |
| QUrl | url () const |
| qreal | zoomFactor () const |
| virtual bool | event (QEvent * e ) |
| QVariant | evaluateJavaScript (const QString & scriptSource ) |
| void | print (QPrinter * printer ) const |
| void | contentsSizeChanged (const QSize & size ) |
| void | iconChanged () |
| void | initialLayoutCompleted () |
| void | javaScriptWindowObjectCleared () |
| void | loadFinished (bool ok ) |
| void | loadStarted () |
| void | pageChanged () |
| void | titleChanged (const QString & title ) |
| void | urlChanged (const QUrl & url ) |
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 ()。另外,若擁有隨時可用的 HTML 內容,可以使用 setHtml () 代替。
The page () function returns a 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 ()) 及要被加載的最初請求 URL (見 requestedUrl ))。這些方法使在加載進程期間齣現 DNS 解答 (或重定嚮) 前後,檢索 URL 成為可能。 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 () 特性。若標題或圖標改變,相應 titleChanged () 和 iconChanged () 信號會被發射。 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() 信號。
另請參閱 QWebPage .
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 |
This property holds the base URL of the frame, can be used to resolve relative URLs.
該特性在 Qt 4.6 引入。
訪問函數:
| QUrl | baseUrl () const |
This property holds the size of the contents in this frame.
訪問函數:
| QSize | contentsSize () const |
另請參閱 contentsSizeChanged ().
Returns true if this frame has keyboard input focus; otherwise, returns false.
該特性在 Qt 4.6 引入。
訪問函數:
| bool | hasFocus () const |
This property holds the icon associated with this frame.
訪問函數:
| QIcon | icon () const |
另請參閱 iconChanged () 和 QWebSettings::iconForUrl ().
The URL requested to loaded by the frame currently viewed. The URL may differ from the one returned by url () if a DNS resolution or a redirection occurs.
該特性在 Qt 4.6 引入。
訪問函數:
| QUrl | requestedUrl () const |
This property holds the position the frame is currently scrolled to.
該特性在 Qt 4.5 引入。
訪問函數:
| QPoint | scrollPosition () const |
| void | setScrollPosition (const QPoint & pos ) |
This property holds the title of the frame as defined by the HTML <title> element.
訪問函數:
| QString | title () const |
另請參閱 titleChanged ().
This property holds the url of the frame currently viewed.
設置此特性清零視圖並加載 URL。
默認情況下,此特性包含空的無效 URL。
訪問函數:
| QUrl | url () const |
| void | setUrl (const QUrl & url ) |
另請參閱 urlChanged ().
This property holds the zoom factor for the frame.
該特性在 Qt 4.5 引入。
訪問函數:
| qreal | zoomFactor () const |
| void | setZoomFactor (qreal factor ) |
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.
The object will never be explicitly deleted by QtWebKit .
這是重載函數。
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 is specified using own .
Returns a list of all frames that are direct children of this frame.
另請參閱 parentFrame ().
[signal]
void
QWebFrame::
contentsSizeChanged
(const
QSize
&
size
)
This signal is emitted when the frame's contents size changes to size .
該函數在 Qt 4.6 引入。
另請參閱 contentsSize ().
Returns the document element of this frame.
The document element provides access to the entire structured content of the frame.
該函數在 Qt 4.6 引入。
[slot]
QVariant
QWebFrame::
evaluateJavaScript
(const
QString
&
scriptSource
)
Evaluates the JavaScript defined by scriptSource using this frame as context and returns the result of the last executed statement.
另請參閱 addToJavaScriptWindowObject () 和 javaScriptWindowObjectCleared ().
[虛擬]
bool
QWebFrame::
event
(
QEvent
*
e
)
重實現自 QObject::event ().
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 ().
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 ().
The name of this frame as defined by the parent frame.
Return the geometry of the frame relative to it's parent frame.
Performs a hit test on the frame contents at the given position pos and returns the hit test result.
[signal]
void
QWebFrame::
iconChanged
()
This signal is emitted when the icon ("favicon") associated with the frame has been loaded.
另請參閱 icon ().
[signal]
void
QWebFrame::
initialLayoutCompleted
()
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.
[signal]
void
QWebFrame::
javaScriptWindowObjectCleared
()
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.
加載 url into this frame.
注意: The view remains the same until enough data has arrived to display the new url .
另請參閱 setUrl (), setHtml (),和 setContent ().
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 ().
[signal]
void
QWebFrame::
loadFinished
(
bool
ok
)
This signal is emitted when a load of this frame is finished. ok 將指示加載是否成功 (或發生任何錯誤)。
該函數在 Qt 4.6 引入。
另請參閱 loadStarted ().
[signal]
void
QWebFrame::
loadStarted
()
This signal is emitted when a new load of this frame is started.
該函數在 Qt 4.6 引入。
另請參閱 loadFinished ().
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 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 引入。
The web page that contains this frame.
另請參閱 pageChanged ().
[signal]
void
QWebFrame::
pageChanged
()
This signal is emitted when this frame has been moved to a different QWebPage .
該函數在 Qt 4.7 引入。
另請參閱 page ().
Returns the parent frame of this frame, or 0 if the frame is the web pages main frame.
這相當於 qobject_cast < QWebFrame *>(frame-> parent ()).
另請參閱 childFrames ().
Returns the position of the frame relative to it's parent frame.
[slot]
void
QWebFrame::
print
(
QPrinter
*
printer
) const
Prints the frame to the given printer .
另請參閱 render ().
Render the frame into painter .
Render the frame into painter clipping to clip .
渲染 layer of the frame using painter clipping to clip .
該函數在 Qt 4.6 引入。
另請參閱 print ().
Returns a dump of the rendering tree. This is mainly useful for debugging html.
Scrolls the frame dx 像素到右側和 dy pixels downward. Both dx and dy 可能為負值。
該函數在 Qt 4.5 引入。
另請參閱 QWebFrame::scrollPosition .
Returns the geometry for the scrollbar with orientation orientation .
If the scrollbar does not exist an empty rect is returned.
該函數在 Qt 4.6 引入。
Returns the maximum value for the scrollbar with orientation orientation , or 0 if no scrollbar is found for orientation .
另請參閱 scrollBarMinimum ().
Returns the minimum value for the scrollbar with orientation orientation .
The minimum value is always 0.
另請參閱 scrollBarMaximum ().
Returns the scrollbar policy for the scrollbar defined by orientation .
另請參閱 setScrollBarPolicy ().
Returns the current value for the scrollbar with orientation orientation , or 0 if no scrollbar is found for orientation .
另請參閱 setScrollBarValue (), scrollBarMinimum (),和 scrollBarMaximum ().
Scrolls the frame to the given anchor 名稱。
該函數在 Qt 4.7 引入。
Returns the frame's security origin.
該函數在 Qt 4.5 引入。
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 .
The data 被立即加載;外部對象是異步加載的。
注意: This method will not affect session or global history for the frame.
Gives keyboard input focus to this frame.
該函數在 Qt 4.6 引入。
另請參閱 hasFocus ().
Sets the content of this frame to html . baseUrl 是可選的和用於解析文檔中的相對 URL,譬如:引用的圖像或樣式錶。
The html 被立即加載;外部對象是異步加載的。
若腳本在 html 運行時間超過默認 (目前 10 秒) 腳本超時,(例如:由於被模態 JavaScript 警報對話框所阻塞),此方法將盡快返迴在超時之後且任何後續 html 將異步加載。
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.
此方便函數相當於 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 () 應該被使用以取而代之。
另請參閱 toHtml (), setContent (),和 load ().
Sets the scrollbar policy for the scrollbar defined by orientation to policy .
另請參閱 scrollBarPolicy ().
設置當前 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 ().
Sets the value of the multiplier used to scale the text in a Web frame to the factor 指定。
另請參閱 textSizeMultiplier ().
Returns the value of the multiplier used to scale the text in a Web frame.
另請參閱 setTextSizeMultiplier ().
[signal]
void
QWebFrame::
titleChanged
(const
QString
&
title
)
This signal is emitted whenever the title of the frame changes. The title 字符串指定新標題。
另請參閱 title ().
Returns the frame's content as HTML, enclosed in HTML and BODY tags.
另請參閱 setHtml () 和 toPlainText ().
Returns the content of this frame converted to plain text, completely stripped of all HTML formatting.
另請參閱 toHtml ().
[signal]
void
QWebFrame::
urlChanged
(const
QUrl
&
url
)
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 ().