QWebPage Class

The QWebPage 類提供用於查看和編輯 Web 文檔的對象。 更多...

頭: #include <QWebPage>
Since: Qt 4.4
繼承: QObject

公共類型

class ChooseMultipleFilesExtensionOption
class ChooseMultipleFilesExtensionReturn
class ErrorPageExtensionOption
class ErrorPageExtensionReturn
class ExtensionOption
class ExtensionReturn
class ViewportAttributes
enum ErrorDomain { QtNetwork, Http, WebKit }
enum Extension { ChooseMultipleFilesExtension, ErrorPageExtension }
enum Feature { Notifications, Geolocation }
enum FindFlag { FindBackward, FindCaseSensitively, FindWrapsAroundDocument, HighlightAllOccurrences }
flags FindFlags
enum LinkDelegationPolicy { DontDelegateLinks, DelegateExternalLinks, DelegateAllLinks }
enum NavigationType { NavigationTypeLinkClicked, NavigationTypeFormSubmitted, NavigationTypeBackOrForward, NavigationTypeReload, NavigationTypeFormResubmitted, NavigationTypeOther }
enum PermissionPolicy { PermissionUnknown, PermissionGrantedByUser, PermissionDeniedByUser }
enum WebAction { NoWebAction, OpenLink, OpenLinkInNewWindow, OpenFrameInNewWindow, ..., AlignRight }
enum WebWindowType { WebBrowserWindow, WebModalDialog }

特性

公共函數

QWebPage (QObject * parent = 0)
~QWebPage ()
QAction * action (WebAction action ) const
quint64 bytesReceived () const
QMenu * createStandardContextMenu ()
QWebFrame * currentFrame () const
virtual bool extension (Extension extension , const ExtensionOption * option = 0, ExtensionReturn * output = 0)
bool findText (const QString & subString , FindFlags options = 0)
bool focusNextPrevChild (bool next )
bool forwardUnsupportedContent () const
QWebFrame * frameAt (const QPoint & pos ) const
bool hasSelection () const
QWebHistory * history () const
QVariant inputMethodQuery (Qt::InputMethodQuery property ) const
bool isContentEditable () const
bool isModified () const
LinkDelegationPolicy linkDelegationPolicy () const
QWebFrame * mainFrame () const
QNetworkAccessManager * networkAccessManager () const
QPalette palette () const
QWebPluginFactory * pluginFactory () const
QSize preferredContentsSize () const
QString selectedHtml () const
QString selectedText () const
void setActualVisibleContentRect (const QRect & rect ) const
void setContentEditable (bool editable )
void setFeaturePermission (QWebFrame * frame , Feature feature , PermissionPolicy policy )
void setForwardUnsupportedContent (bool forward )
void setLinkDelegationPolicy (LinkDelegationPolicy policy )
void setNetworkAccessManager (QNetworkAccessManager * manager )
void setPalette (const QPalette & palette )
void setPluginFactory (QWebPluginFactory * factory )
void setPreferredContentsSize (const QSize & size ) const
void setView (QWidget * view )
void setViewportSize (const QSize & size ) const
QWebSettings * settings () const
QStringList supportedContentTypes () const
bool supportsContentType (const QString & mimeType ) const
virtual bool supportsExtension (Extension extension ) const
bool swallowContextMenuEvent (QContextMenuEvent * event )
quint64 totalBytes () const
virtual void triggerAction (WebAction action , bool checked = false)
QUndoStack * undoStack () const
void updatePositionDependentActions (const QPoint & pos )
QWidget * view () const
ViewportAttributes viewportAttributesForSize (const QSize & availableSize ) const
QSize viewportSize () const

重實現公共函數

virtual bool event (QEvent * ev )

公共槽

bool shouldInterruptJavaScript ()

信號

void applicationCacheQuotaExceeded (QWebSecurityOrigin * origin , quint64 defaultOriginQuota )
void contentsChanged ()
void databaseQuotaExceeded (QWebFrame * frame , QString databaseName )
void downloadRequested (const QNetworkRequest & request )
void featurePermissionRequestCanceled (QWebFrame * frame , QWebPage::Feature feature )
void featurePermissionRequested (QWebFrame * frame , QWebPage::Feature feature )
void frameCreated (QWebFrame * frame )
void geometryChangeRequested (const QRect & geom )
void linkClicked (const QUrl & url )
void linkHovered (const QString & link , const QString & title , const QString & textContent )
void loadFinished (bool ok )
void loadProgress (int progress )
void loadStarted ()
void menuBarVisibilityChangeRequested (bool visible )
void microFocusChanged ()
void printRequested (QWebFrame * frame )
void repaintRequested (const QRect & dirtyRect )
void restoreFrameStateRequested (QWebFrame * frame )
void saveFrameStateRequested (QWebFrame * frame , QWebHistoryItem * item )
void scrollRequested (int dx , int dy , const QRect & rectToScroll )
void selectionChanged ()
void statusBarMessage (const QString & text )
void statusBarVisibilityChangeRequested (bool visible )
void toolBarVisibilityChangeRequested (bool visible )
void unsupportedContent (QNetworkReply * reply )
void viewportChangeRequested ()
void windowCloseRequested ()

保護函數

virtual bool acceptNavigationRequest (QWebFrame * frame , const QNetworkRequest & request , NavigationType type )
virtual QString chooseFile (QWebFrame * parentFrame , const QString & suggestedFile )
virtual QObject * createPlugin (const QString & classid , const QUrl & url , const QStringList & paramNames , const QStringList & paramValues )
virtual QWebPage * createWindow (WebWindowType type )
virtual void javaScriptAlert (QWebFrame * frame , const QString & msg )
virtual bool javaScriptConfirm (QWebFrame * frame , const QString & msg )
virtual void javaScriptConsoleMessage (const QString & message , int lineNumber , const QString & sourceID )
virtual bool javaScriptPrompt (QWebFrame * frame , const QString & msg , const QString & defaultValue , QString * result )
virtual QString userAgentForUrl (const QUrl & url ) const
int qWebKitMajorVersion ()
int qWebKitMinorVersion ()
QString qWebKitVersion ()

QTWEBKIT_VERSION
QTWEBKIT_VERSION_CHECK
QTWEBKIT_VERSION_STR

額外繼承成員

詳細描述

The QWebPage 類提供用於查看和編輯 Web 文檔的對象。

QWebPage holds a main frame responsible for web content, settings, the history of navigated links and actions. This class can be used, together with QWebFrame , to provide functionality like QWebView in a widget-less environment.

QWebPage 的 API 非常類似 QWebView ,仍提供常用功能像 action () (稱為 pageAction () 在 QWebView ), triggerAction (), findText () 和 settings (). More QWebView -like functions can be found in the main frame of QWebPage , obtained via the mainFrame () function. For example, the load (), setUrl () 和 setHtml () functions for QWebPage can be accessed using QWebFrame .

The loadStarted () signal is emitted when the page begins to load.The loadProgress () signal, on the other hand, is emitted whenever an element of the web page completes loading, such as an embedded image, a script, etc. Finally, the loadFinished () signal is emitted when the page contents are loaded completely, independent of script execution or page rendering. Its argument, either true or false, indicates whether or not the load operation succeeded.

Using QWebPage in a Widget-less Environment

Before you begin painting a QWebPage object, you need to set the size of the viewport by calling setViewportSize (). Then, you invoke the main frame's render function ( QWebFrame::render ()). An example of this is shown in the code snippet below.

Suppose we have a Thumbnail class as follows:

class Thumbnailer : public QObject
{
    Q_OBJECT
public:
    Thumbnailer(const QUrl &url);
signals:
    void finished();
private slots:
    void render();
private:
    QWebPage page;
};
					

The Thumbnail 's constructor takes in a url . We connect our QWebPage 對象的 loadFinished() signal to our private slot, render() .

Thumbnailer::Thumbnailer(const QUrl &url)
{
    page.mainFrame()->load(url);
    connect(&page, SIGNAL(loadFinished(bool)),
        this, SLOT(render()));
}
					

The render() function shows how we can paint a thumbnail using a QWebPage 對象。

void Thumbnailer::render()
{
    page.setViewportSize(page.mainFrame()->contentsSize());
    QImage image(page.viewportSize(), QImage::Format_ARGB32);
    QPainter painter(&image);
    page.mainFrame()->render(&painter);
    painter.end();
    QImage thumbnail = image.scaled(400, 400);
    thumbnail.save("thumbnail.png");
    emit finished();
}
					

We begin by setting the viewportSize and then we instantiate a QImage 對象, image , with the same size as our viewportSize . This image is then sent as a parameter to painter . Next, we render the contents of the main frame and its subframes into painter . Finally, we save the scaled image.

另請參閱 QWebFrame .

成員類型文檔編製

enum QWebPage:: ErrorDomain

This enum describes the domain of an ErrorPageExtensionOption object (i.e. the layer in which the error occurred).

常量 描述
QWebPage::QtNetwork 0 The error occurred in the QtNetwork layer; the error code is of type QNetworkReply::NetworkError .
QWebPage::Http 1 The error occurred in the HTTP layer; the error code is a HTTP status code (see QNetworkRequest::HttpStatusCodeAttribute ).
QWebPage::WebKit 2 The error is an internal WebKit 錯誤。

該枚舉在 Qt 4.6 引入或被修改。

enum QWebPage:: Extension

This enum describes the types of extensions that the page can support. Before using these extensions, you should verify that the extension is supported by calling supportsExtension ().

常量 描述
QWebPage::ChooseMultipleFilesExtension 0 Whether the web page supports multiple file selection. This extension is invoked when the web content requests one or more file names, for example as a result of the user clicking on a "file upload" button in a HTML form where multiple file selection is allowed.
QWebPage::ErrorPageExtension 1 Whether the web page can provide an error page when loading fails. (introduced in Qt 4.6)

另請參閱 ChooseMultipleFilesExtensionOption , ChooseMultipleFilesExtensionReturn , ErrorPageExtensionOption ,和 ErrorPageExtensionReturn .

enum QWebPage:: Feature

enum QWebPage:: FindFlag
flags QWebPage:: FindFlags

此枚舉描述的選項可用於 findText () 函數。來自以下列錶中的選項可以 OR 在一起:

常量 描述
QWebPage::FindBackward 1 嚮後搜索,而不是嚮前。
QWebPage::FindCaseSensitively 2 默認情況下 findText () works case insensitive. Specifying this option changes the behaviour to a case sensitive find operation.
QWebPage::FindWrapsAroundDocument 4 使 findText () restart from the beginning of the document if the end was reached and the text was not found.
QWebPage::HighlightAllOccurrences 8 Highlights all existing occurrences of a specific string. (This value was introduced in 4.6.)

FindFlags 類型是 typedef 對於 QFlags <FindFlag>。它存儲 FindFlag 值的 OR (或) 組閤。

enum QWebPage:: LinkDelegationPolicy

This enum defines the delegation policies a webpage can have when activating links and emitting the linkClicked () 信號。

常量 描述
QWebPage::DontDelegateLinks 0 No links are delegated. Instead, QWebPage tries to handle them all.
QWebPage::DelegateExternalLinks 1 When activating links that point to documents not stored on the local filesystem or an equivalent - such as the Qt resource system - then linkClicked () 發射。
QWebPage::DelegateAllLinks 2 Whenever a link is activated the linkClicked () 信號發射。

另請參閱 QWebPage::linkDelegationPolicy .

This enum describes the types of navigation available when browsing through hyperlinked documents.

常量 描述
QWebPage::NavigationTypeLinkClicked 0 The user clicked on a link or pressed return on a focused link.
QWebPage::NavigationTypeFormSubmitted 1 The user activated a submit button for an HTML form.
QWebPage::NavigationTypeBackOrForward 2 Navigation to a previously shown document in the back or forward history is requested.
QWebPage::NavigationTypeReload 3 The user activated the reload action.
QWebPage::NavigationTypeFormResubmitted 4 An HTML form was submitted a second time.
QWebPage::NavigationTypeOther 5 A navigation to another document using a method not listed above.

另請參閱 acceptNavigationRequest ().

enum QWebPage:: PermissionPolicy

enum QWebPage:: WebAction

此枚舉描述可以在網頁上履行的動作類型。

Actions only have an effect when they are applicable. The availability of actions can be be determined by checking isEnabled() 在返迴動作通過 action ().

One method of enabling the text editing, cursor movement, and text selection actions is by setting contentEditable to true.

常量 描述
QWebPage::NoWebAction -1 沒有動作被觸發。
QWebPage::OpenLink 0 打開當前鏈接。
QWebPage::OpenLinkInNewWindow 1 Open the current link in a new window.
QWebPage::OpenFrameInNewWindow 2 Replicate the current frame in a new window.
QWebPage::DownloadLinkToDisk 3 Download the current link to the disk.
QWebPage::CopyLinkToClipboard 4 Copy the current link to the clipboard.
QWebPage::OpenImageInNewWindow 5 Open the highlighted image in a new window.
QWebPage::DownloadImageToDisk 6 Download the highlighted image to the disk.
QWebPage::CopyImageToClipboard 7 Copy the highlighted image to the clipboard.
QWebPage::CopyImageUrlToClipboard 68 Copy the highlighted image's URL to the clipboard.
QWebPage::Back 8 在導航鏈接曆史中後退導航。
QWebPage::Forward 9 在導航鏈接曆史中前進導航。
QWebPage::Stop 10 停止加載當前頁麵。
QWebPage::StopScheduledPageRefresh 67 Stop all pending page refresh/redirect requests.
QWebPage::Reload 11 重新加載當前頁麵。
QWebPage::ReloadAndBypassCache 53 Reload the current page, but do not use any local cache. (Added in Qt 4.6)
QWebPage::Cut 12 把目前選中內容剪切到剪貼闆。
QWebPage::Copy 13 把目前選中內容拷貝到剪貼闆。
QWebPage::Paste 14 從剪貼闆粘貼內容。
QWebPage::Undo 15 撤消上一編輯動作。
QWebPage::Redo 16 重做上一編輯動作。
QWebPage::MoveToNextChar 17 把光標移動到下一字符。
QWebPage::MoveToPreviousChar 18 把光標移動到上一字符。
QWebPage::MoveToNextWord 19 把光標移動到下一單詞。
QWebPage::MoveToPreviousWord 20 把光標移動到上一單詞。
QWebPage::MoveToNextLine 21 Move the cursor to the next line.
QWebPage::MoveToPreviousLine 22 Move the cursor to the previous line.
QWebPage::MoveToStartOfLine 23 Move the cursor to the start of the line.
QWebPage::MoveToEndOfLine 24 Move the cursor to the end of the line.
QWebPage::MoveToStartOfBlock 25 Move the cursor to the start of the block.
QWebPage::MoveToEndOfBlock 26 Move the cursor to the end of the block.
QWebPage::MoveToStartOfDocument 27 Move the cursor to the start of the document.
QWebPage::MoveToEndOfDocument 28 Move the cursor to the end of the document.
QWebPage::SelectNextChar 29 Select to the next character.
QWebPage::SelectPreviousChar 30 Select to the previous character.
QWebPage::SelectNextWord 31 Select to the next word.
QWebPage::SelectPreviousWord 32 Select to the previous word.
QWebPage::SelectNextLine 33 Select to the next line.
QWebPage::SelectPreviousLine 34 Select to the previous line.
QWebPage::SelectStartOfLine 35 Select to the start of the line.
QWebPage::SelectEndOfLine 36 Select to the end of the line.
QWebPage::SelectStartOfBlock 37 Select to the start of the block.
QWebPage::SelectEndOfBlock 38 Select to the end of the block.
QWebPage::SelectStartOfDocument 39 Select to the start of the document.
QWebPage::SelectEndOfDocument 40 Select to the end of the document.
QWebPage::DeleteStartOfWord 41 Delete to the start of the word.
QWebPage::DeleteEndOfWord 42 Delete to the end of the word.
QWebPage::SetTextDirectionDefault 43 Set the text direction to the default direction.
QWebPage::SetTextDirectionLeftToRight 44 Set the text direction to left-to-right.
QWebPage::SetTextDirectionRightToLeft 45 Set the text direction to right-to-left.
QWebPage::ToggleBold 46 Toggle the formatting between bold and normal weight.
QWebPage::ToggleItalic 47 Toggle the formatting between italic and normal style.
QWebPage::ToggleUnderline 48 Toggle underlining.
QWebPage::InspectElement 49 Show the Web Inspector with the currently highlighted HTML element.
QWebPage::InsertParagraphSeparator 50 Insert a new paragraph.
QWebPage::InsertLineSeparator 51 Insert a new line.
QWebPage::SelectAll 52 Selects all content.
QWebPage::PasteAndMatchStyle 54 采用當前樣式從剪貼闆粘貼內容。
QWebPage::RemoveFormat 55 Removes formatting and style.
QWebPage::ToggleStrikethrough 56 Toggle the formatting between strikethrough and normal style.
QWebPage::ToggleSubscript 57 Toggle the formatting between subscript and baseline.
QWebPage::ToggleSuperscript 58 Toggle the formatting between supercript and baseline.
QWebPage::InsertUnorderedList 59 Toggles the selection between an ordered list and a normal block.
QWebPage::InsertOrderedList 60 Toggles the selection between an ordered list and a normal block.
QWebPage::Indent 61 Increases the indentation of the currently selected format block by one increment.
QWebPage::Outdent 62 Decreases the indentation of the currently selected format block by one increment.
QWebPage::AlignCenter 63 Applies center alignment to content.
QWebPage::AlignJustified 64 Applies full justification to content.
QWebPage::AlignLeft 65 Applies left justification to content.
QWebPage::AlignRight 66 Applies right justification to content.

enum QWebPage:: WebWindowType

此枚舉描述可以創建的窗口類型通過 createWindow () 函數。

常量 描述
QWebPage::WebBrowserWindow 0 The window is a regular web browser window.
QWebPage::WebModalDialog 1 The window acts as modal dialog.

特性文檔編製

contentEditable : bool

This property holds whether the content in this QWebPage is editable or not.

If this property is enabled the contents of the page can be edited by the user through a visible cursor. If disabled (the default) only HTML elements in the web page with their contenteditable attribute set are editable.

該特性在 Qt 4.5 引入。

訪問函數:

bool isContentEditable () const
void setContentEditable (bool editable )

另請參閱 modified , contentsChanged (),和 WebAction .

forwardUnsupportedContent : bool

This property holds whether QWebPage should forward unsupported content.

If enabled, the unsupportedContent () signal is emitted with a network reply that can be used to read the content.

If disabled, the download of such content is aborted immediately.

By default unsupported content is not forwarded.

訪問函數:

bool forwardUnsupportedContent () const
void setForwardUnsupportedContent (bool forward )

hasSelection : const bool

此特性保持此頁麵是否包含選定內容。

訪問函數:

bool hasSelection () const

另請參閱 selectionChanged ().

linkDelegationPolicy : LinkDelegationPolicy

This property holds how QWebPage should delegate the handling of links through the linkClicked() signal.

The default is to delegate no links.

訪問函數:

LinkDelegationPolicy linkDelegationPolicy () const
void setLinkDelegationPolicy (LinkDelegationPolicy policy )

modified : const bool

This property holds whether the page contains unsubmitted form data, or the contents have been changed.

默認情況下,此特性為 false。

訪問函數:

bool isModified () const

另請參閱 contentsChanged (), contentEditable ,和 undoStack ().

palette : QPalette

This property holds the page's palette.

The base brush of the palette is used to draw the background of the main frame.

By default, this property contains the application's default palette.

訪問函數:

QPalette palette () const
void setPalette (const QPalette & palette )

preferredContentsSize : QSize

This property holds a custom size used for laying out the page contents.

By default all pages are laid out using the viewport of the page as the base.

As pages mostly are designed for desktop usage, they often do not layout properly on small devices as the contents require a certain view width. For this reason it is common to use a different layout size and then scale the contents to fit within the actual view.

If this property is set to a valid size, this size is used for all layout needs instead of the size of the viewport.

Setting an invalid size, makes the page fall back to using the viewport size for layout.

該特性在 Qt 4.6 引入。

訪問函數:

QSize preferredContentsSize () const
void setPreferredContentsSize (const QSize & size ) const

另請參閱 viewportSize .

selectedHtml : const QString

此特性保持目前選中的 HTML。

默認情況下,此特性包含空字符串。

該特性在 Qt 4.8 引入。

訪問函數:

QString selectedHtml () const

另請參閱 selectionChanged () 和 selectedText ().

selectedText : const QString

此特性保持當前選中的文本。

默認情況下,此特性包含空字符串。

訪問函數:

QString selectedText () const

另請參閱 selectionChanged () 和 selectedHtml ().

viewportSize : QSize

This property holds the size of the viewport.

The size affects for example the visibility of scrollbars if the document is larger than the viewport.

By default, for a newly-created Web page, this property contains a size with zero width and height.

訪問函數:

QSize viewportSize () const
void setViewportSize (const QSize & size ) const

另請參閱 QWebFrame::render () 和 preferredContentsSize .

成員函數文檔編製

QWebPage:: QWebPage ( QObject * parent = 0)

構造空的 QWebPage 采用父級 parent .

QWebPage:: ~QWebPage ()

銷毀 Web 頁麵。

[virtual protected] bool QWebPage:: acceptNavigationRequest ( QWebFrame * frame , const QNetworkRequest & request , NavigationType type )

此函數被調用每當 WebKit requests to navigate frame to the resource specified by request 通過指定導航類型 type .

frame is a null pointer then navigation to a new window is requested. If the request is accepted createWindow () will be called.

The default implementation interprets the page's linkDelegationPolicy 並發射 linkClicked accordingly or returns true to let QWebPage handle the navigation itself.

另請參閱 createWindow ().

QAction * QWebPage:: action ( WebAction action ) const

返迴 QAction 為指定 WebAction action .

動作歸 QWebPage 但可以通過改變其特性定製外觀。

QWebPage 還負責實現動作,以便觸發時在頁麵履行相應動作。

另請參閱 triggerAction ().

[signal] void QWebPage:: applicationCacheQuotaExceeded ( QWebSecurityOrigin * origin , quint64 defaultOriginQuota )

This signal is emitted whenever the web site is asking to store data to the application cache database databaseName and the quota allocated to that web site is exceeded.

quint64 QWebPage:: bytesReceived () const

Returns the number of bytes that were received from the network to render the current page.

另請參閱 totalBytes () 和 loadProgress ().

[virtual protected] QString QWebPage:: chooseFile ( QWebFrame * parentFrame , const QString & suggestedFile )

This function is called when the web content requests a file name, for example as a result of the user clicking on a "file upload" button in a HTML form.

A suggested filename may be provided in suggestedFile . The frame originating the request is provided as parentFrame .

另請參閱 ChooseMultipleFilesExtension .

[signal] void QWebPage:: contentsChanged ()

This signal is emitted whenever the text in form elements changes as well as other editable content.

該函數在 Qt 4.5 引入。

另請參閱 contentEditable , modified , QWebFrame::toHtml (),和 QWebFrame::toPlainText ().

[virtual protected] QObject * QWebPage:: createPlugin (const QString & classid , const QUrl & url , const QStringList & paramNames , const QStringList & paramValues )

此函數被調用每當 WebKit encounters a HTML object element with type "application/x-qt-plugin". It is called regardless of the value of QWebSettings::PluginsEnabled classid , url , paramNames and paramValues correspond to the HTML object element attributes and child elements to configure the embeddable object.

QMenu * QWebPage:: createStandardContextMenu ()

This function creates the standard context menu which is shown when the user clicks on the web page with the right mouse button. It is called from the default contextMenuEvent() handler. The popup menu's ownership is transferred to the caller.

該函數在 Qt 4.5 引入。

[virtual protected] QWebPage * QWebPage:: createWindow ( WebWindowType type )

此函數被調用每當 WebKit wants to create a new window of the given type , for example when a JavaScript program requests to open a document in a new window.

若新窗口可以被創建,新窗口的 QWebPage 被返迴;否則 null 指針被返迴。

若網頁關聯視圖為 QWebView 對象,則默認實現把請求轉發給 QWebView 's createWindow() function; otherwise it returns a null pointer.

type is WebModalDialog , the application must call setWindowModality( Qt::ApplicationModal ) on the new window.

注意: In the cases when the window creation is being triggered by JavaScript, apart from reimplementing this method application must also set the JavaScriptCanOpenWindows attribute of QWebSettings to true in order for it to get called.

另請參閱 acceptNavigationRequest () 和 QWebView::createWindow ().

QWebFrame * QWebPage:: currentFrame () const

Returns the frame currently active.

另請參閱 mainFrame () 和 frameCreated ().

[signal] void QWebPage:: databaseQuotaExceeded ( QWebFrame * frame , QString databaseName )

This signal is emitted whenever the web site shown in frame is asking to store data to the database databaseName and the quota allocated to that web site is exceeded.

該函數在 Qt 4.5 引入。

另請參閱 QWebDatabase .

[signal] void QWebPage:: downloadRequested (const QNetworkRequest & request )

This signal is emitted when the user decides to download a link. The url of the link as well as additional meta-information is contained in request .

另請參閱 unsupportedContent ().

[虛擬] bool QWebPage:: event ( QEvent * ev )

重實現自 QObject::event ().

[虛擬] bool QWebPage:: extension ( Extension extension , const ExtensionOption * option = 0, ExtensionReturn * output = 0)

This virtual function can be reimplemented in a QWebPage subclass to provide support for extensions. The option argument is provided as input to the extension; the output results can be stored in output .

The behavior of this function is determined by extension option and output values are typically casted to the corresponding types (for example, ChooseMultipleFilesExtensionOption and ChooseMultipleFilesExtensionReturn for ChooseMultipleFilesExtension ).

可以調用 supportsExtension () to check if an extension is supported by the page.

Returns true if the extension was called successfully; otherwise returns false.

另請參閱 supportsExtension () 和 Extension .

[signal] void QWebPage:: featurePermissionRequestCanceled ( QWebFrame * frame , QWebPage::Feature feature )

[signal] void QWebPage:: featurePermissionRequested ( QWebFrame * frame , QWebPage::Feature feature )

bool QWebPage:: findText (const QString & subString , FindFlags options = 0)

查找指定字符串, subString ,在頁麵使用給定 options .

HighlightAllOccurrences flag is passed, the function will highlight all occurrences that exist in the page. All subsequent calls will extend the highlight, rather than replace it, with occurrences of the new string.

HighlightAllOccurrences flag is not passed, the function will select an occurrence and all subsequent calls will replace the current occurrence with the next one.

要清除選定,隻需傳遞空字符串。

返迴 true 若 subString was found; otherwise returns false.

bool QWebPage:: focusNextPrevChild ( bool next )

類似於 QWidget::focusNextPrevChild () it focuses the next focusable web element if next is true; otherwise the previous element is focused.

Returns true if it can find a new focusable element, or false if it can't.

QWebFrame * QWebPage:: frameAt (const QPoint & pos ) const

Returns the frame at the given point pos , or 0 if there is no frame at that position.

該函數在 Qt 4.6 引入。

另請參閱 mainFrame () 和 currentFrame ().

[signal] void QWebPage:: frameCreated ( QWebFrame * frame )

This signal is emitted whenever the page creates a new frame .

另請參閱 currentFrame ().

[signal] void QWebPage:: geometryChangeRequested (const QRect & geom )

此信號被發射每當文檔希望把頁麵位置和大小更改為 geom 。這會發生,例如透過 JavaScript。

QWebHistory * QWebPage:: history () const

返迴指嚮導航網頁的視圖曆史的指針。

QVariant QWebPage:: inputMethodQuery ( Qt::InputMethodQuery property ) const

This method is used by the input method to query a set of properties of the page to be able to support complex input method operations as support for surrounding text and reconversions.

property 指定查詢特性。

另請參閱 QWidget::inputMethodEvent (), QInputMethodEvent ,和 QInputContext .

[virtual protected] void QWebPage:: javaScriptAlert ( QWebFrame * frame , const QString & msg )

This function is called whenever a JavaScript program running inside frame calls the alert() function with the message msg .

默認實現展示消息, msg ,采用 QMessageBox::information .

[virtual protected] bool QWebPage:: javaScriptConfirm ( QWebFrame * frame , const QString & msg )

This function is called whenever a JavaScript program running inside frame calls the confirm() function with the message, msg . Returns true if the user confirms the message; otherwise returns false.

默認實現執行查詢使用 QMessageBox::information with QMessageBox::Yes and QMessageBox::No 按鈕。

[virtual protected] void QWebPage:: javaScriptConsoleMessage (const QString & message , int lineNumber , const QString & sourceID )

This function is called whenever a JavaScript program tries to print a message 到 Web 瀏覽器控製颱。

For example in case of evaluation errors the source URL may be provided in sourceID as well as the lineNumber .

The default implementation prints nothing.

[virtual protected] bool QWebPage:: javaScriptPrompt ( QWebFrame * frame , const QString & msg , const QString & defaultValue , QString * result )

This function is called whenever a JavaScript program running inside frame tries to prompt the user for input. The program may provide an optional message, msg , as well as a default value for the input in defaultValue .

If the prompt was cancelled by the user the implementation should return false; otherwise the result should be written to result and true should be returned. If the prompt was not cancelled by the user, the implementation should return true and the result string must not be null.

默認實現使用 QInputDialog::getText ().

[signal] void QWebPage:: linkClicked (const QUrl & url )

This signal is emitted whenever the user clicks on a link and the page's linkDelegationPolicy property is set to delegate the link handling for the specified url .

By default no links are delegated and are handled by QWebPage 代替。

注意: This signal possibly won't be emitted for clicked links which use JavaScript to trigger navigation.

另請參閱 linkHovered ().

[signal] void QWebPage:: linkHovered (const QString & link , const QString & title , const QString & textContent )

此信號被發射當鼠標懸停鏈接上時。

link contains the link url. title is the link element's title, if it is specified in the markup. textContent provides text within the link element, e.g., text inside an HTML anchor tag.

When the mouse leaves the link element the signal is emitted with empty parameters.

另請參閱 linkClicked ().

[signal] void QWebPage:: loadFinished ( bool ok )

This signal is emitted when the page finishes loading content. This signal is independant of script execution or page rendering. ok 將指示加載是否成功 (或發生任何錯誤)。

另請參閱 loadStarted () 和 ErrorPageExtension .

[signal] void QWebPage:: loadProgress ( int progress )

此信號被發射當全局進度狀態改變時。當前值被提供由 progress 並縮放到 0 - 100,其是默認範圍為 QProgressBar 。它纍計所有子級幀的變化。

另請參閱 bytesReceived ().

[signal] void QWebPage:: loadStarted ()

此信號被發射當頁麵開始加載內容。

另請參閱 loadFinished ().

QWebFrame * QWebPage:: mainFrame () const

Returns the main frame of the page.

The main frame provides access to the hierarchy of sub-frames and is also needed if you want to explicitly render a web page into a given painter.

另請參閱 currentFrame ().

This signal is emitted whenever the visibility of the menubar in a web browser window that hosts QWebPage should be changed to visible .

[signal] void QWebPage:: microFocusChanged ()

This signal is emitted when for example the position of the cursor in an editable form element changes. It is used to inform input methods about the new on-screen position where the user is able to enter text. This signal is usually connected to the QWidget::updateMicroFocus () 槽。

QNetworkAccessManager * QWebPage:: networkAccessManager () const

返迴 QNetworkAccessManager that is responsible for serving network requests for this QWebPage .

另請參閱 setNetworkAccessManager ().

QWebPluginFactory * QWebPage:: pluginFactory () const

返迴 QWebPluginFactory that is responsible for creating plugins embedded into this QWebPage . If no plugin factory is installed a null pointer is returned.

另請參閱 setPluginFactory ().

[signal] void QWebPage:: printRequested ( QWebFrame * frame )

This signal is emitted whenever the page requests the web browser to print frame , for example through the JavaScript window.print() 調用。

另請參閱 QWebFrame::print () 和 QPrintPreviewDialog .

[signal] void QWebPage:: repaintRequested (const QRect & dirtyRect )

This signal is emitted whenever this QWebPage should be updated. It's useful when rendering a QWebPage without a QWebView or QGraphicsWebView . dirtyRect contains the area that needs to be updated. To paint the QWebPage get the mainFrame () and call the render( QPainter *, const QRegion &) method with the dirtyRect as the second parameter.

另請參閱 mainFrame () 和 view ().

[signal] void QWebPage:: restoreFrameStateRequested ( QWebFrame * frame )

This signal is emitted when the load of frame is finished and the application may now update its state accordingly.

該函數在 Qt 4.5 引入。

[signal] void QWebPage:: saveFrameStateRequested ( QWebFrame * frame , QWebHistoryItem * item )

This signal is emitted shortly before the history of navigated pages in frame is changed, for example when navigating back in the history.

提供的 QWebHistoryItem , item , holds the history entry of the frame before the change.

A potential use-case for this signal is to store custom data in the QWebHistoryItem associated to the frame, using QWebHistoryItem::setUserData ().

該函數在 Qt 4.5 引入。

[signal] void QWebPage:: scrollRequested ( int dx , int dy , const QRect & rectToScroll )

This signal is emitted whenever the content given by rectToScroll needs to be scrolled dx and dy downwards and no view was set.

另請參閱 view ().

[signal] void QWebPage:: selectionChanged ()

This signal is emitted whenever the selection changes, either interactively or programmatically (e.g. by calling triggerAction () with a selection action).

另請參閱 selectedText ().

void QWebPage:: setActualVisibleContentRect (const QRect & rect ) const

void QWebPage:: setFeaturePermission ( QWebFrame * frame , Feature feature , PermissionPolicy policy )

void QWebPage:: setNetworkAccessManager ( QNetworkAccessManager * manager )

設置 QNetworkAccessManager manager responsible for serving network requests for this QWebPage .

注意: It is currently not supported to change the network access manager after the QWebPage has used it. The results of doing this are undefined.

另請參閱 networkAccessManager ().

void QWebPage:: setPluginFactory ( QWebPluginFactory * factory )

設置 QWebPluginFactory factory responsible for creating plugins embedded into this QWebPage .

Note: The plugin factory is only used if the QWebSettings::PluginsEnabled 屬性被啓用。

另請參閱 pluginFactory ().

void QWebPage:: setView ( QWidget * view )

設置 view 關聯網頁。

另請參閱 view ().

QWebSettings * QWebPage:: settings () const

返迴指嚮頁麵設置對象的指針。

另請參閱 QWebSettings::globalSettings ().

[slot] bool QWebPage:: shouldInterruptJavaScript ()

This function is called when a JavaScript program is running for a long period of time.

If the user wanted to stop the JavaScript the implementation should return true; otherwise false.

默認實現執行查詢使用 QMessageBox::information with QMessageBox::Yes and QMessageBox::No 按鈕。

警告: Because of binary compatibility constraints, this function is not virtual. If you want to provide your own implementation in a QWebPage subclass, reimplement the shouldInterruptJavaScript() slot in your subclass instead. QtWebKit will dynamically detect the slot and call it.

該函數在 Qt 4.6 引入。

[signal] void QWebPage:: statusBarMessage (const QString & text )

This signal is emitted when the statusbar text is changed by the page.

[signal] void QWebPage:: statusBarVisibilityChangeRequested ( bool visible )

This signal is emitted whenever the visibility of the statusbar in a web browser window that hosts QWebPage should be changed to visible .

QStringList QWebPage:: supportedContentTypes () const

Returns the list of all content types supported by QWebPage .

bool QWebPage:: supportsContentType (const QString & mimeType ) const

返迴 true 若 QWebPage can handle the given mimeType ; otherwise, returns false.

[虛擬] bool QWebPage:: supportsExtension ( Extension extension ) const

This virtual function returns true if the web page supports extension ;否則 false 被返迴。

另請參閱 extension ().

bool QWebPage:: swallowContextMenuEvent ( QContextMenuEvent * event )

Filters the context menu event, event , through handlers for scrollbars and custom event handlers in the web page. Returns true if the event was handled; otherwise false.

A web page may swallow a context menu event through a custom event handler, allowing for context menus to be implemented in HTML/JavaScript. This is used by Google Maps ,例如。

[signal] void QWebPage:: toolBarVisibilityChangeRequested ( bool visible )

This signal is emitted whenever the visibility of the toolbar in a web browser window that hosts QWebPage should be changed to visible .

quint64 QWebPage:: totalBytes () const

Returns the total number of bytes that were received from the network to render the current page, including extra content such as embedded images.

另請參閱 bytesReceived ().

[虛擬] void QWebPage:: triggerAction ( WebAction action , bool checked = false)

此函數可以被調用以觸發指定 action . It is also called by QtWebKit if the user triggers the action, for example through a context menu item.

action is a checkable action then checked specified whether the action is toggled or not.

另請參閱 action ().

QUndoStack * QWebPage:: undoStack () const

Returns a pointer to the undo stack used for editable content.

另請參閱 modified .

[signal] void QWebPage:: unsupportedContent ( QNetworkReply * reply )

此信號發射,當 WebKit cannot handle a link the user navigated to or a web server's response includes a "Content-Disposition" header with the 'attachment' directive. If "Content-Disposition" is present in reply , the web server is indicating that the client should prompt the user to save the content regardless of content-type. See RFC 2616 sections 19.5.1 for details about Content-Disposition.

At signal emission time the meta-data of the QNetworkReply reply 可用。

注意: The receiving slot is responsible for deleting the QNetworkReply reply .

注意: This signal is only emitted if the forwardUnsupportedContent property is set to true.

另請參閱 downloadRequested ().

void QWebPage:: updatePositionDependentActions (const QPoint & pos )

Updates the page's actions depending on the position pos . For example if pos is over an image element the CopyImageToClipboard action is enabled.

[virtual protected] QString QWebPage:: userAgentForUrl (const QUrl & url ) const

This function is called when a user agent for HTTP requests is needed. You can reimplement this function to dynamically return different user agents for different URLs, based on the url 參數。

The default implementation returns the following value:

"Mozilla/5.0 (%Platform%%Security%%Subplatform%) AppleWebKit/%WebKitVersion% (KHTML, like Gecko) %AppVersion Safari/%WebKitVersion%"

On mobile platforms such as Symbian S60 and Maemo, "Mobile Safari" is used instead of "Safari".

In this string the following values are replaced at run-time:

  • %Platform% expands to the windowing system followed by "; " if it is not Windows (e.g. "X11; ").
  • %Security% expands to "N; " if SSL is disabled.
  • %Subplatform% expands to the operating system version (e.g. "Windows NT 6.1" or "Intel Mac OS X 10.5").
  • %WebKitVersion% is the version of WebKit the application was compiled against.
  • %AppVersion% expands to QCoreApplication::applicationName ()/ QCoreApplication::applicationVersion () if they're set; otherwise defaulting to Qt and the current Qt version.

QWidget * QWebPage:: view () const

返迴與網頁關聯的視圖 Widget。

另請參閱 setView ().

ViewportAttributes QWebPage:: viewportAttributesForSize (const QSize & availableSize ) const

Computes the optimal viewport configuration given the availableSize , when user interface components are disregarded.

The configuration is also dependent on the device screen size which is obtained automatically. For testing purposes the size can be overridden by setting two environment variables QTWEBKIT_DEVICE_WIDTH and QTWEBKIT_DEVICE_HEIGHT, which both needs to be set.

The ViewportAttributes includes a pixel density ratio, which will also be exposed to the web author though the -webkit-pixel-ratio media feature. This is the ratio between 1 density-independent pixel (DPI) and physical pixels.

A density-independent pixel is equivalent to one physical pixel on a 160 DPI screen, so on our platform assumes that as the baseline density.

The conversion of DIP units to screen pixels is quite simple:

pixels = DIPs * (density / 160).

Thus, on a 240 DPI screen, 1 DIPs would equal 1.5 physical pixels.

An invalid instance will be returned in the case an empty size is passed to the method.

注意: The density is automatically obtained from the DPI of the screen where the page is being shown, but as many X11 servers are reporting wrong DPI, it is possible to override it using QX11Info::setAppDpiY ().

[signal] void QWebPage:: viewportChangeRequested ()

Page authors can provide the supplied values by using the viewport meta tag. More information about this can be found at Safari Reference Library: Using the Viewport Meta Tag .

該函數在 Qt 4.8 引入。

另請參閱 QWebPage::ViewportAttributes , setPreferredContentsSize (),和 QGraphicsWebView::setScale ().

[signal] void QWebPage:: windowCloseRequested ()

此信號被發射每當頁麵請求關閉 Web 瀏覽器窗口時,例如透過 JavaScript window.close() 調用。

相關非成員

int qWebKitMajorVersion ()

Returns the 'major' version number of WebKit at run-time as an integer (for example, 531). This is the version of WebKit the application was compiled against.

該函數在 Qt 4.6 引入。

另請參閱 qWebKitVersion ().

int qWebKitMinorVersion ()

Returns the 'minor' version number of WebKit at run-time as an integer (for example, 3). This is the version of WebKit the application was compiled against.

該函數在 Qt 4.6 引入。

另請參閱 qWebKitVersion ().

QString qWebKitVersion ()

Returns the version number of WebKit at run-time as a string (for example, "531.3").

This version is commonly used in WebKit based browsers as part of the user agent string. Web servers and JavaScript might use it to identify the presence of certain WebKit engine features and behaviour.

The evolution of this version is bound to the releases of Apple's Safari browser. For a version specific to the QtWebKit library, see QTWEBKIT_VERSION

該函數在 Qt 4.6 引入。

另請參閱 QWebPage::userAgentForUrl ().

宏文檔編製

QTWEBKIT_VERSION

This macro expands a numeric value of the form 0xMMNNPP (MM = major, NN = minor, PP = patch) that specifies QtWebKit 's version number. For example, if you compile your application against QtWebKit 2.1.2, the QTWEBKIT_VERSION macro will expand to 0x020102.

You can use QTWEBKIT_VERSION to use the latest QtWebKit API where available.

另請參閱 QT_VERSION .

QTWEBKIT_VERSION_CHECK

Turns the major, minor and patch numbers of a version into an integer, 0xMMNNPP (MM = major, NN = minor, PP = patch). This can be compared with another similarly processed version id, for example in a preprocessor statement:

#if QTWEBKIT_VERSION >= QTWEBKIT_VERSION_CHECK(2, 1, 0)
// code to use API new in QtWebKit 2.1.0
#endif
					

QTWEBKIT_VERSION_STR

This macro expands to a string that specifies QtWebKit 's version number (for example, "2.1.2"). This is the version against which the application is compiled.

另請參閱 QTWEBKIT_VERSION .