QWebView Class Reference

[ QtWebKit module]

The QWebView class provides a widget that is used to view and edit web documents. 更多...

继承 QWidget .

方法

Qt Signals


详细描述

The QWebView class provides a widget that is used to view and edit web documents.

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 with the 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 () 代替。

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 () 信号被发射 when the view has loaded completely. It's argument - either true or false - indicates load success or failure.

page () 函数返回 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 object with the settings () function. With QWebSettings , you can change the default fonts, enable or disable features such as JavaScript and 插件。

可以访问 HTML 文档的标题采用 title () property. Additionally, a web site 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 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 对象 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() 信号。

If you want to provide support for web sites that allow the user to open new windows, such as pop-up windows, you can subclass QWebView and reimplement the 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 属性。 Nevertheless, QtWebKit depends on QtGui , so you should use a QApplication 而不是 QCoreApplication .


方法文档编制

QWebView.__init__ ( self , QWidget   parent  = None)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

构造空 QWebView with parent parent .

另请参阅 load ().

QWebView.back ( self )

This method is also a Qt slot with the C++ signature void back() .

Convenience slot that loads the previous document in the list of documents built by navigating links. Does nothing if there is no previous document.

它相当于

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

另请参阅 forward () and pageAction ().

QWebView.changeEvent ( self , QEvent )

重实现自 QWidget.changeEvent ().

QWebView.contextMenuEvent ( self , QContextMenuEvent )

重实现自 QWidget.contextMenuEvent ().

QWebView QWebView.createWindow ( self , 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 ().

QWebView.dragEnterEvent ( self , QDragEnterEvent )

重实现自 QWidget.dragEnterEvent ().

QWebView.dragLeaveEvent ( self , QDragLeaveEvent )

重实现自 QWidget.dragLeaveEvent ().

QWebView.dragMoveEvent ( self , QDragMoveEvent )

重实现自 QWidget.dragMoveEvent ().

QWebView.dropEvent ( self , QDropEvent )

重实现自 QWidget.dropEvent ().

bool QWebView.event ( self , QEvent )

重实现自 QObject.event ().

bool QWebView.findText ( self , QString  subString , QWebPage.FindFlags   options  = 0)

查找指定字符串, subString , in the page, using the given 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 ().

QWebView.focusInEvent ( self , QFocusEvent )

重实现自 QWidget.focusInEvent ().

bool QWebView.focusNextPrevChild ( self , bool  next )

重实现自 QWidget.focusNextPrevChild ().

QWebView.focusOutEvent ( self , QFocusEvent )

重实现自 QWidget.focusOutEvent ().

QWebView.forward ( self )

This method is also a Qt slot with the C++ signature void forward() .

Convenience slot that loads the next document in the list of documents built by navigating links. Does nothing if there is no next document.

它相当于

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

另请参阅 back () 和 pageAction ().

bool QWebView.hasSelection ( self )

QWebHistory QWebView.history ( self )

Returns a pointer to the view's history of navigated web 页面。

它相当于

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

QIcon QWebView.icon ( self )

QWebView.inputMethodEvent ( self , QInputMethodEvent )

重实现自 QWidget.inputMethodEvent ().

QVariant QWebView.inputMethodQuery ( self , Qt.InputMethodQuery   property )

重实现自 QWidget.inputMethodQuery ().

bool QWebView.isModified ( self )

QWebView.keyPressEvent ( self , QKeyEvent )

重实现自 QWidget.keyPressEvent ().

QWebView.keyReleaseEvent ( self , QKeyEvent )

重实现自 QWidget.keyReleaseEvent ().

QWebView.load ( self , QUrl   url )

加载指定 url 并显示它。

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

另请参阅 setUrl (), url (), urlChanged (),和 QUrl.fromUserInput ().

QWebView.load ( self , QNetworkRequest   request , QNetworkAccessManager.Operation   operation  = QNetworkAccessManager.GetOperation, 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 ().

QWebView.mouseDoubleClickEvent ( self , QMouseEvent )

重实现自 QWidget.mouseDoubleClickEvent ().

QWebView.mouseMoveEvent ( self , QMouseEvent )

重实现自 QWidget.mouseMoveEvent ().

QWebView.mousePressEvent ( self , QMouseEvent )

重实现自 QWidget.mousePressEvent ().

QWebView.mouseReleaseEvent ( self , QMouseEvent )

重实现自 QWidget.mouseReleaseEvent ().

QWebPage QWebView.page ( self )

返回指向底层 Web 页面的指针。

另请参阅 setPage ().

QAction QWebView.pageAction ( self , QWebPage.WebAction   action )

返回指针指向 QAction that encapsulates the specified web action action .

QWebView.paintEvent ( self , QPaintEvent   ev )

重实现自 QWidget.paintEvent ().

QWebView.print_ ( self , QPrinter   printer )

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

打印主框架到给定 printer .

另请参阅 QWebFrame.print () 和 QPrintPreviewDialog .

QWebView.reload ( self )

This method is also a Qt slot with the C++ signature void reload() .

重新加载当前文档。

另请参阅 stop (), pageAction (),和 loadStarted ().

QPainter.RenderHints QWebView.renderHints ( self )

QWebView.resizeEvent ( self , QResizeEvent   e )

重实现自 QWidget.resizeEvent ().

QString QWebView.selectedHtml ( self )

QString QWebView.selectedText ( self )

QWebView.setContent ( self , QByteArray   data , QString  mimeType  = QString(), 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.

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

data is loaded immediately; external objects are loaded asynchronously.

另请参阅 load (), setHtml (),和 QWebFrame.toHtml ().

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

将 Web 视图内容设为指定 html .

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

html is loaded immediately; external objects are 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. Alternatively, the encoding can also be specified by the web server.

This is a convenience function equivalent to setContent(html, "text/html", baseUrl).

警告: This function works only for HTML, for other mime types (i.e. XHTML, SVG) setContent () should be used 代替。

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

QWebView.setPage ( self , QWebPage   page )

Makes page 成为 Web 视图的新网页。

父级 QObject of the provided page remains the owner of the object. If the current page is a child of the web view, it will be deleted.

另请参阅 page ().

QWebView.setRenderHint ( self , QPainter.RenderHint   hint , bool  enabled  = True)

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

该函数在 Qt 4.6 引入。

另请参阅 renderHints and QPainter.renderHints ().

QWebView.setRenderHints ( self , QPainter.RenderHints   hints )

QWebView.setTextSizeMultiplier ( self , float  factor )

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

另请参阅 textSizeMultiplier ().

QWebSettings QWebView.settings ( self )

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

它相当于

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

另请参阅 QWebSettings.globalSettings ().

QWebView.setUrl ( self , QUrl   url )

QWebView.setZoomFactor ( self , float  factor )

QSize QWebView.sizeHint ( self )

重实现自 QWidget.sizeHint ().

QWebView.stop ( self )

This method is also a Qt slot with the C++ signature void stop() .

停止加载文档的方便槽。

它相当于

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

另请参阅 reload (), pageAction (),和 loadFinished ().

float QWebView.textSizeMultiplier ( self )

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

另请参阅 setTextSizeMultiplier ().

QString QWebView.title ( self )

QWebView.triggerPageAction ( self , QWebPage.WebAction   action , bool  checked  = False)

触发指定 action . If it is a checkable action the specified checked 假定状态。

The following example triggers the copy action and therefore copies any selected text to the clipboard.

     view->triggerAction(QWebPage.Copy);
			

另请参阅 pageAction ().

QUrl QWebView.url ( self )

QWebView.wheelEvent ( self , QWheelEvent )

重实现自 QWidget.wheelEvent ().

float QWebView.zoomFactor ( self )


Qt Signal Documentation

void iconChanged ()

This is the default overload of this signal.

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 ().

void linkClicked (const QUrl&)

This is the default overload of this signal.

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 loadFinished (bool)

This is the default overload of this signal.

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

另请参阅 loadStarted ().

void loadProgress (int)

This is the default overload of this signal.

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 and scales from 0 to 100, which is the default range of QProgressBar .

另请参阅 loadStarted () 和 loadFinished ().

void loadStarted ()

This is the default overload of this signal.

This signal is emitted when a new load of the page is started.

另请参阅 loadProgress () 和 loadFinished ().

void selectionChanged ()

This is the default overload of this signal.

此信号被发射每当选定改变。

另请参阅 selectedText ().

void statusBarMessage (const QString&)

This is the default overload of this signal.

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

void titleChanged (const QString&)

This is the default overload of this signal.

此信号被发射每当 title of the main frame changes.

另请参阅 title ().

void urlChanged (const QUrl&)

This is the default overload of this signal.

此信号被发射当 url of the view 改变。

另请参阅 url () 和 load ().