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 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 .
此特性保持此页面是否包含选定内容。
默认情况下,此特性为 false。
访问函数:
| bool | hasSelection () const |
另请参阅 selectionChanged ().
This property holds the icon associated with the web page currently viewed.
默认情况下,此特性包含 null 图标。
访问函数:
| QIcon | icon () const |
另请参阅 iconChanged () 和 QWebSettings::iconForUrl ().
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 |
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 ().
此特性保持目前选中的 HTML。
默认情况下,此特性包含空字符串。
该特性在 Qt 4.8 引入。
访问函数:
| QString | selectedHtml () const |
另请参阅 findText (), selectionChanged (),和 selectedText ().
此特性保持当前选中的文本。
默认情况下,此特性包含空字符串。
访问函数:
| QString | selectedText () const |
另请参阅 findText (), selectionChanged (),和 selectedHtml ().
This property holds the title of the web page currently viewed.
默认情况下,此特性包含空字符串。
访问函数:
| QString | title () const |
另请参阅 titleChanged ().
This property holds the url of the web page currently viewed.
设置此特性清零视图并加载 URL。
默认情况下,此特性包含空的无效 URL。
访问函数:
| QUrl | url () const |
| void | setUrl (const QUrl & url ) |
另请参阅 load () 和 urlChanged ().
此特性保持视图缩放因子。
该特性在 Qt 4.5 引入。
访问函数:
| qreal | zoomFactor () const |
| void | setZoomFactor (qreal factor ) |
构造空的 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 ().
查找指定字符串, 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 ().
返回指向导航网页的视图历史的指针。
它相当于
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 ().
加载指定 url 并显示它。
注意: The view remains the same until enough data has arrived to display the new url .
另请参阅 setUrl (), url (), urlChanged (),和 QUrl::fromUserInput ().
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 ().
返回指向底层 Web 页面的指针。
另请参阅 setPage ().
返回指针指向 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 ().
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 ().
将 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 ().
使 page 成为 Web 视图的新网页。
父级 QObject 为提供页面仍然是对象所有者。若当前页面是 Web 视图子页面,则删除它。
另请参阅 page ().
若 enabled is true, enables the specified render hint ; otherwise disables it.
该函数在 Qt 4.6 引入。
另请参阅 renderHints and QPainter::renderHints ().
Sets the value of the multiplier used to scale the text in a Web page to the factor 指定。
另请参阅 textSizeMultiplier ().
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 ().
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 ().
触发指定 action . If it is a checkable action the specified checked 假定状态。
以下范例触发拷贝动作,因此把任何选中文本拷贝到剪贴板。
view->triggerAction(QWebPage::Copy);
另请参阅 pageAction ().
[signal]
void
QWebView::
urlChanged
(const
QUrl
&
url
)
此信号发射当 url 对于视图改变。
[virtual protected]
void
QWebView::
wheelEvent
(
QWheelEvent
*
ev
)
重实现自 QWidget::wheelEvent ().