QWebView Class

The QWebView 類提供用於查看和編輯 Web 文檔的 Widget。 更多...

頭: #include <QWebView>
Since: Qt 4.4
繼承: QWidget

特性

公共函數

QWebView (QWidget * parent = 0)
virtual ~QWebView ()
bool findText (const QString & subString , QWebPage::FindFlags options = 0)
bool hasSelection () const
QWebHistory * history () const
QIcon icon () const
bool isModified () const
void load (const QUrl & url )
void load (const QNetworkRequest & request , QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, const QByteArray & body = QByteArray())
QWebPage * page () const
QAction * pageAction (QWebPage::WebAction action ) const
QPainter::RenderHints renderHints () const
QString selectedHtml () const
QString selectedText () const
void setContent (const QByteArray & data , const QString & mimeType = QString(), const QUrl & baseUrl = QUrl())
void setHtml (const QString & html , const QUrl & baseUrl = QUrl())
void setPage (QWebPage * page )
void setRenderHint (QPainter::RenderHint hint , bool enabled = true)
void setRenderHints (QPainter::RenderHints hints )
void setTextSizeMultiplier (qreal factor )
void setUrl (const QUrl & url )
void setZoomFactor (qreal factor )
QWebSettings * settings () const
qreal textSizeMultiplier () const
QString title () const
void triggerPageAction (QWebPage::WebAction action , bool checked = false)
QUrl url () const
qreal zoomFactor () const

重實現公共函數

virtual bool event (QEvent * e )
virtual QVariant inputMethodQuery (Qt::InputMethodQuery property ) const
virtual QSize sizeHint () const

公共槽

void back ()
void forward ()
void print (QPrinter * printer ) const
void reload ()
void stop ()

信號

void iconChanged ()
void linkClicked (const QUrl & url )
void loadFinished (bool ok )
void loadProgress (int progress )
void loadStarted ()
void selectionChanged ()
void statusBarMessage (const QString & text )
void titleChanged (const QString & title )
void urlChanged (const QUrl & url )

保護函數

virtual QWebView * createWindow (QWebPage::WebWindowType type )

重實現保護函數

virtual void changeEvent (QEvent * e )
virtual void contextMenuEvent (QContextMenuEvent * ev )
virtual void dragEnterEvent (QDragEnterEvent * ev )
virtual void dragLeaveEvent (QDragLeaveEvent * ev )
virtual void dragMoveEvent (QDragMoveEvent * ev )
virtual void dropEvent (QDropEvent * ev )
virtual void focusInEvent (QFocusEvent * ev )
virtual bool focusNextPrevChild (bool next )
virtual void focusOutEvent (QFocusEvent * ev )
virtual void inputMethodEvent (QInputMethodEvent * e )
virtual void keyPressEvent (QKeyEvent * ev )
virtual void keyReleaseEvent (QKeyEvent * ev )
virtual void mouseDoubleClickEvent (QMouseEvent * ev )
virtual void mouseMoveEvent (QMouseEvent * ev )
virtual void mousePressEvent (QMouseEvent * ev )
virtual void mouseReleaseEvent (QMouseEvent * ev )
virtual void paintEvent (QPaintEvent * ev )
virtual void resizeEvent (QResizeEvent * e )
virtual void wheelEvent (QWheelEvent * ev )

額外繼承成員

詳細描述

The QWebView 類提供用於查看和編輯 Web 文檔的 Widget。

QWebView is the main widget component of the QtWebKit web browsing module. It can be used in various applications to display web content live from the Internet.

A web site can be loaded onto QWebView 采用 load () function. Like all Qt widgets, the show () function must be invoked in order to display QWebView . The snippet below illustrates this:

    QWebView *view = new QWebView(parent);
    view->load(QUrl("http://qt-project.org"));
    view->show();
					

另外, setUrl () can also be used to load a web site. If you have the HTML content readily available, you can use setHtml () 代替。

The loadStarted () signal is emitted when the view begins loading. The loadProgress () signal, on the other hand, is emitted whenever an element of the web view completes loading, such as an embedded image, a script, etc. Finally, the loadFinished () signal is emitted when the view has loaded completely. It's argument - either true or false - indicates load success or failure.

The page () function returns a pointer to the web page object. See QWebView 元素 for an explanation of how the web page is related to the view. To modify your web view's settings, you can access the QWebSettings 對象采用 settings () function. With QWebSettings , you can change the default fonts, enable or disable features such as JavaScript and plugins.

可以訪問 HTML 文檔的標題采用 title () property. Additionally, a web site may also specify an icon, which can be accessed using the icon () 特性。若標題或圖標改變,相應 titleChanged () 和 iconChanged () 信號會被發射。 textSizeMultiplier () property can be used to change the overall size of the text displayed in the web view.

If you require a custom context menu, you can implement it by reimplementing contextMenuEvent() and populating your QMenu with the actions obtained from pageAction (). More functionality such as reloading the view, copying selected text to the clipboard, or pasting into the view, is also encapsulated within the QAction objects returned by pageAction (). These actions can be programmatically triggered using triggerPageAction (). Alternatively, the actions can be added to a toolbar or a menu directly. QWebView maintains the state of the returned actions but allows modification of action properties such as text or icon .

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

若希望為允許用戶打開新窗口 (譬如:彈齣窗口) 的網站提供支持,可以子類 QWebView 並重實現 createWindow () 函數。

QWebView 元素

QWebView consists of other objects such as QWebFrame and QWebPage . The flowchart below shows these elements are related.

注意: It is possible to use QWebPage and QWebFrame , without using QWebView , if you do not require QWidget attributes. Nevertheless, QtWebKit depends on QtGui , so you should use a QApplication 而不是 QCoreApplication .

另請參閱 Previewer Example , Web 瀏覽器 , Form Extractor Example , Google Chat Example ,和 Fancy Browser Example .

特性文檔編製

hasSelection : const bool

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

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

訪問函數:

bool hasSelection () const

另請參閱 selectionChanged ().

icon : const QIcon

This property holds the icon associated with the web page currently viewed.

默認情況下,此特性包含 null 圖標。

訪問函數:

QIcon icon () const

另請參閱 iconChanged () 和 QWebSettings::iconForUrl ().

modified : const bool

This property holds whether the document was modified by the user.

Parts of HTML documents can be editable for example through the contenteditable 屬性在 HTML 元素。

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

訪問函數:

bool isModified () const

renderHints : QPainter::RenderHints

This property holds the default render hints for the view.

這些提示用於初始化 QPainter before painting the Web page.

QPainter::TextAntialiasing and QPainter::SmoothPixmapTransform are enabled by default.

注意: This property is not available on Symbian. However, the getter and setter functions can still be used directly.

該特性在 Qt 4.6 引入。

訪問函數:

QPainter::RenderHints renderHints () const
void setRenderHints (QPainter::RenderHints hints )

另請參閱 QPainter::renderHints ().

selectedHtml : const QString

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

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

該特性在 Qt 4.8 引入。

訪問函數:

QString selectedHtml () const

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

selectedText : const QString

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

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

訪問函數:

QString selectedText () const

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

title : const QString

This property holds the title of the web page currently viewed.

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

訪問函數:

QString title () const

另請參閱 titleChanged ().

url : QUrl

This property holds the url of the web page currently viewed.

設置此特性清零視圖並加載 URL。

默認情況下,此特性包含空的無效 URL。

訪問函數:

QUrl url () const
void setUrl (const QUrl & url )

另請參閱 load () 和 urlChanged ().

zoomFactor : qreal

此特性保持視圖縮放因子。

該特性在 Qt 4.5 引入。

訪問函數:

qreal zoomFactor () const
void setZoomFactor (qreal factor )

成員函數文檔編製

QWebView:: QWebView ( QWidget * parent = 0)

構造空的 QWebView 采用父級 parent .

另請參閱 load ().

[虛擬] QWebView:: ~QWebView ()

銷毀 Web 視圖。

[slot] void QWebView:: back ()

方便槽,用於把先前文檔加載進由導航鏈接構建的文檔列錶。什麼都不做,若沒有先前文檔。

它相當於

    view->page()->triggerPageAction(QWebPage::GoBack);
					

另請參閱 forward () 和 pageAction ().

[virtual protected] void QWebView:: changeEvent ( QEvent * e )

重實現自 QWidget::changeEvent ().

[virtual protected] void QWebView:: contextMenuEvent ( QContextMenuEvent * ev )

重實現自 QWidget::contextMenuEvent ().

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

This function is called from the createWindow() method of the associated QWebPage , each time the page wants to create a new window of the given type . This might be the result, for example, of a JavaScript request to open a document in a new window.

注意: If the createWindow() method of the associated page is reimplemented, this method is not called, unless explicitly done so in the reimplementation.

注意: 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.

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

[virtual protected] void QWebView:: dragEnterEvent ( QDragEnterEvent * ev )

重實現自 QWidget::dragEnterEvent ().

[virtual protected] void QWebView:: dragLeaveEvent ( QDragLeaveEvent * ev )

重實現自 QWidget::dragLeaveEvent ().

[virtual protected] void QWebView:: dragMoveEvent ( QDragMoveEvent * ev )

重實現自 QWidget::dragMoveEvent ().

[virtual protected] void QWebView:: dropEvent ( QDropEvent * ev )

重實現自 QWidget::dropEvent ().

[虛擬] bool QWebView:: event ( QEvent * e )

重實現自 QObject::event ().

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

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

If the 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.

If the 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.

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

[virtual protected] void QWebView:: focusInEvent ( QFocusEvent * ev )

重實現自 QWidget::focusInEvent ().

[virtual protected] bool QWebView:: focusNextPrevChild ( bool next )

重實現自 QWidget::focusNextPrevChild ().

[virtual protected] void QWebView:: focusOutEvent ( QFocusEvent * ev )

重實現自 QWidget::focusOutEvent ().

[slot] void QWebView:: forward ()

方便槽,用於把下一文檔加載進由導航鏈接構建的文檔列錶。什麼都不做,若沒有下一文檔。

它相當於

    view->page()->triggerPageAction(QWebPage::GoForward);
					

另請參閱 back () 和 pageAction ().

QWebHistory * QWebView:: history () const

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

它相當於

    view->page()->history();
					

[signal] void QWebView:: iconChanged ()

This signal is emitted whenever the icon of the page is loaded or changes.

In order for icons to be loaded, you will need to set an icon database path using QWebSettings::setIconDatabasePath ().

另請參閱 icon () 和 QWebSettings::setIconDatabasePath ().

[virtual protected] void QWebView:: inputMethodEvent ( QInputMethodEvent * e )

重實現自 QWidget::inputMethodEvent ().

[虛擬] QVariant QWebView:: inputMethodQuery ( Qt::InputMethodQuery property ) const

重實現自 QWidget::inputMethodQuery ().

[virtual protected] void QWebView:: keyPressEvent ( QKeyEvent * ev )

重實現自 QWidget::keyPressEvent ().

[virtual protected] void QWebView:: keyReleaseEvent ( QKeyEvent * ev )

重實現自 QWidget::keyReleaseEvent ().

[signal] void QWebView:: 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 .

另請參閱 QWebPage::linkDelegationPolicy ().

void QWebView:: load (const QUrl & url )

加載指定 url 並顯示它。

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

另請參閱 setUrl (), url (), urlChanged (),和 QUrl::fromUserInput ().

void QWebView:: load (const QNetworkRequest & request , QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, const QByteArray & body = QByteArray())

Loads a network request, request , 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 url.

另請參閱 url () 和 urlChanged ().

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

This signal is emitted when a load of the page is finished. ok 將指示加載是否成功 (或發生任何錯誤)。

另請參閱 loadStarted ().

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

This signal is emitted every time an element in the web page completes loading and the overall loading progress advances.

This signal tracks the progress of all child frames.

當前值被提供由 progress 並縮放到 0 - 100,其是默認範圍為 QProgressBar .

另請參閱 loadStarted () 和 loadFinished ().

[signal] void QWebView:: loadStarted ()

此信號被發射當頁麵的新加載開始時。

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

[virtual protected] void QWebView:: mouseDoubleClickEvent ( QMouseEvent * ev )

重實現自 QWidget::mouseDoubleClickEvent ().

[virtual protected] void QWebView:: mouseMoveEvent ( QMouseEvent * ev )

重實現自 QWidget::mouseMoveEvent ().

[virtual protected] void QWebView:: mousePressEvent ( QMouseEvent * ev )

重實現自 QWidget::mousePressEvent ().

[virtual protected] void QWebView:: mouseReleaseEvent ( QMouseEvent * ev )

重實現自 QWidget::mouseReleaseEvent ().

QWebPage * QWebView:: page () const

返迴指嚮底層 Web 頁麵的指針。

另請參閱 setPage ().

QAction * QWebView:: pageAction ( QWebPage::WebAction action ) const

返迴指針指嚮 QAction 封裝指定的 Web 動作 action .

[virtual protected] void QWebView:: paintEvent ( QPaintEvent * ev )

重實現自 QWidget::paintEvent ().

[slot] void QWebView:: print ( QPrinter * printer ) const

打印主框架到給定 printer .

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

[slot] void QWebView:: reload ()

重新加載當前文檔。

另請參閱 stop (), pageAction (),和 loadStarted ().

[virtual protected] void QWebView:: resizeEvent ( QResizeEvent * e )

重實現自 QWidget::resizeEvent ().

[signal] void QWebView:: selectionChanged ()

此信號發射,每當選定改變時。

另請參閱 selectedText ().

void QWebView:: setContent (const QByteArray & data , const QString & mimeType = QString(), const QUrl & baseUrl = QUrl())

Sets the content of the web view 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 被立即加載;外部對象是異步加載的。

另請參閱 load (), setHtml (),和 QWebFrame::toHtml ().

void QWebView:: setHtml (const QString & html , const QUrl & baseUrl = QUrl())

將 Web 視圖內容設為指定 html .

External objects such as stylesheets or images referenced in the HTML document are located relative to baseUrl .

The 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. Alternatively, the encoding can also be specified by the web server.

此方便函數相當於 setContent (html, "text/html", baseUrl).

警告: This function works only for HTML, for other mime types (i.e. XHTML, SVG) setContent () 應該被使用以取而代之。

另請參閱 load (), setContent (), QWebFrame::toHtml (),和 QWebFrame::setContent ().

void QWebView:: setPage ( QWebPage * page )

使 page 成為 Web 視圖的新網頁。

父級 QObject 為提供頁麵仍然是對象所有者。若當前頁麵是 Web 視圖子頁麵,則刪除它。

另請參閱 page ().

void QWebView:: setRenderHint ( QPainter::RenderHint hint , bool enabled = true)

enabled is true, enables the specified render hint ; otherwise disables it.

該函數在 Qt 4.6 引入。

另請參閱 renderHints and QPainter::renderHints ().

void QWebView:: setTextSizeMultiplier ( qreal factor )

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

另請參閱 textSizeMultiplier ().

QWebSettings * QWebView:: settings () const

Returns a pointer to the view/page specific settings object.

它相當於

    view->page()->settings();
					

另請參閱 QWebSettings::globalSettings ().

[虛擬] QSize QWebView:: sizeHint () const

重實現自 QWidget::sizeHint ().

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

This signal is emitted when the status bar text is changed by the page.

[slot] void QWebView:: stop ()

停止加載文檔的方便槽。

它相當於

    view->page()->triggerPageAction(QWebPage::Stop);
					

另請參閱 reload (), pageAction (),和 loadFinished ().

qreal QWebView:: textSizeMultiplier () const

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

另請參閱 setTextSizeMultiplier ().

[signal] void QWebView:: titleChanged (const QString & title )

此信號發射,每當 title of the main frame changes.

另請參閱 title ().

void QWebView:: triggerPageAction ( QWebPage::WebAction action , bool checked = false)

觸發指定 action . If it is a checkable action the specified checked 假定狀態。

以下範例觸發拷貝動作,因此把任何選中文本拷貝到剪貼闆。

    view->triggerAction(QWebPage::Copy);
					

另請參閱 pageAction ().

[signal] void QWebView:: urlChanged (const QUrl & url )

此信號發射,當 url 對於視圖改變。

另請參閱 url () 和 load ().

[virtual protected] void QWebView:: wheelEvent ( QWheelEvent * ev )

重實現自 QWidget::wheelEvent ().