The QWebView class provides a widget that is used to view and edit web documents.QtWebKit. More...
#include <qwebview.h>

Public Slots | |
| void | stop () |
| void | back () |
| void | forward () |
| void | reload () |
| void | print (QPrinter *) const |
Signals | |
| void | loadStarted () |
| void | loadProgress (int progress) |
| void | loadFinished (bool) |
| void | titleChanged (const QString &title) |
| void | statusBarMessage (const QString &text) |
| void | linkClicked (const QUrl &) |
| void | selectionChanged () |
| void | iconChanged () |
| void | urlChanged (const QUrl &) |
Public Member Functions | |
| QWebView (QWidget *parent=0) | |
| virtual | ~QWebView () |
| QWebPage * | page () const |
| void | setPage (QWebPage *page) |
| void | load (const QUrl &url) |
| void | load (const QNetworkRequest &request, QNetworkAccessManager::Operation operation=QNetworkAccessManager::GetOperation, const QByteArray &body=QByteArray()) |
| void | setHtml (const QString &html, const QUrl &baseUrl=QUrl()) |
| void | setContent (const QByteArray &data, const QString &mimeType=QString(), const QUrl &baseUrl=QUrl()) |
| QWebHistory * | history () const |
| QWebSettings * | settings () const |
| QString | title () const |
| void | setUrl (const QUrl &url) |
| QUrl | url () const |
| QIcon | icon () const |
| QString | selectedText () const |
| QAction * | pageAction (QWebPage::WebAction action) const |
| void | triggerPageAction (QWebPage::WebAction action, bool checked=false) |
| bool | isModified () const |
| QVariant | inputMethodQuery (Qt::InputMethodQuery property) const |
| QSize | sizeHint () const |
| qreal | zoomFactor () const |
| void | setZoomFactor (qreal factor) |
| void | setTextSizeMultiplier (qreal factor) |
| qreal | textSizeMultiplier () const |
| QPainter::RenderHints | renderHints () const |
| void | setRenderHints (QPainter::RenderHints hints) |
| void | setRenderHint (QPainter::RenderHint hint, bool enabled=true) |
| bool | findText (const QString &subString, QWebPage::FindFlags options=0) |
| virtual bool | event (QEvent *) |
| void | setShowFPS (bool enabled=true) |
Protected Member Functions | |
| void | resizeEvent (QResizeEvent *) |
| void | paintEvent (QPaintEvent *) |
| virtual QWebView * | createWindow (QWebPage::WebWindowType type) |
| virtual void | changeEvent (QEvent *) |
| virtual void | mouseMoveEvent (QMouseEvent *) |
| virtual void | mousePressEvent (QMouseEvent *) |
| virtual void | mouseDoubleClickEvent (QMouseEvent *) |
| virtual void | mouseReleaseEvent (QMouseEvent *) |
| virtual void | contextMenuEvent (QContextMenuEvent *) |
| virtual void | wheelEvent (QWheelEvent *) |
| virtual void | keyPressEvent (QKeyEvent *) |
| virtual void | keyReleaseEvent (QKeyEvent *) |
| virtual void | dragEnterEvent (QDragEnterEvent *) |
| virtual void | dragLeaveEvent (QDragLeaveEvent *) |
| virtual void | dragMoveEvent (QDragMoveEvent *) |
| virtual void | dropEvent (QDropEvent *) |
| virtual void | focusInEvent (QFocusEvent *) |
| virtual void | focusOutEvent (QFocusEvent *) |
| virtual void | inputMethodEvent (QInputMethodEvent *) |
| virtual bool | focusNextPrevChild (bool next) |
Properties | |
| QString | title |
| the title of the web page currently viewed | |
| QUrl | url |
| the url of the web page currently viewed | |
| QIcon | icon |
| the icon associated with the web page currently viewed | |
| QString | selectedText |
| the text currently selected | |
| bool | modified |
| whether the document was modified by the user | |
| qreal | textSizeMultiplier |
| the scaling factor for all text in the frame | |
| qreal | zoomFactor |
| the zoom factor for the view | |
| QPainter::RenderHints | renderHints |
| the default render hints for the view | |
Private Attributes | |
| QWebViewPrivate * | d |
| int | frameCount |
| qreal | fps |
| QTime | FPSTime |
| bool | showFPS |
| QRect | FPSRect |
Friends | |
| class | QWebPage |
The QWebView class provides a widget that is used to view and edit web documents.
QtWebKit.
The image below shows QWebView previewed in with a Nokia website.
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:
webkitsnippets/simple/main.cpp Using QWebView
Alternatively, setUrl() can also be used to load a web site. If you have the HTML content readily available, you can use setHtml() instead.
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 {Elements of 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 plugins.
The title of an HTML document can be accessed with the 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() and 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 {QWidget::}{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 {QAction::}{text} or {QAction::}{icon}.
A QWebView can be printed onto a QPrinter using the print() function. This function is marked as a slot and can be conveniently connected to {QPrintPreviewDialog}'s {QPrintPreviewDialog::}{paintRequested()} signal.
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() function.
Definition at line 50 of file qwebview.h.
| QWebView::QWebView | ( | QWidget * | parent = 0 |
) | [explicit] |
Constructs an empty QWebView with parent parent.
Definition at line 309 of file qwebview.cpp.
| QWebView::~QWebView | ( | ) | [virtual] |
Destroys the web view.
Definition at line 360 of file qwebview.cpp.
References QWebPagePrivate::client, QWebPage::d, d, QWebViewPrivate::page, and QWebPagePrivate::view.
| void QWebView::back | ( | ) | [slot] |
Convenience slot that loads the previous document in the list of documents built by navigating links. Does nothing if there is no previous document.
It is equivalent to
webkitsnippets/qtwebkit_qwebview_snippet.cpp 4
Definition at line 897 of file qwebview.cpp.
References QWebPage::Back, d, QWebViewPrivate::page, and QWebPage::triggerAction().

| void QWebView::changeEvent | ( | QEvent * | e | ) | [protected, virtual] |
Definition at line 1198 of file qwebview.cpp.
References d, QWebViewPrivate::page, and QWebPage::setPalette().

| void QWebView::contextMenuEvent | ( | QContextMenuEvent * | ev | ) | [protected, virtual] |
Definition at line 1067 of file qwebview.cpp.
References d, QWebPage::event(), and QWebViewPrivate::page.

| QWebView * QWebView::createWindow | ( | QWebPage::WebWindowType | type | ) | [protected, virtual] |
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.
Definition at line 994 of file qwebview.cpp.
| void QWebView::dragEnterEvent | ( | QDragEnterEvent * | ev | ) | [protected, virtual] |
Definition at line 1132 of file qwebview.cpp.
References d, QWebPage::event(), and QWebViewPrivate::page.

| void QWebView::dragLeaveEvent | ( | QDragLeaveEvent * | ev | ) | [protected, virtual] |
Definition at line 1142 of file qwebview.cpp.
References d, QWebPage::event(), and QWebViewPrivate::page.

| void QWebView::dragMoveEvent | ( | QDragMoveEvent * | ev | ) | [protected, virtual] |
Definition at line 1152 of file qwebview.cpp.
References d, QWebPage::event(), and QWebViewPrivate::page.

| void QWebView::dropEvent | ( | QDropEvent * | ev | ) | [protected, virtual] |
Definition at line 1162 of file qwebview.cpp.
References d, QWebPage::event(), and QWebViewPrivate::page.

| bool QWebView::event | ( | QEvent * | e | ) | [virtual] |
Definition at line 811 of file qwebview.cpp.
References QWebPagePrivate::client, QWebPage::d, d, QWebPage::event(), QWebViewPrivate::page, QWebPage::swallowContextMenuEvent(), and QWebPage::updatePositionDependentActions().

| bool QWebView::findText | ( | const QString & | subString, | |
| QWebPage::FindFlags | options = 0 | |||
| ) |
Finds the specified string, 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.
To clear the selection, just pass an empty string.
Returns true if subString was found; otherwise returns false.
Definition at line 802 of file qwebview.cpp.
References d, QWebPage::findText(), and QWebViewPrivate::page.

| void QWebView::focusInEvent | ( | QFocusEvent * | ev | ) | [protected, virtual] |
Definition at line 1112 of file qwebview.cpp.
References d, QWebPage::event(), and QWebViewPrivate::page.

| bool QWebView::focusNextPrevChild | ( | bool | next | ) | [protected, virtual] |
Definition at line 1172 of file qwebview.cpp.
References d, QWebPage::focusNextPrevChild(), and QWebViewPrivate::page.

| void QWebView::focusOutEvent | ( | QFocusEvent * | ev | ) | [protected, virtual] |
Definition at line 1122 of file qwebview.cpp.
References d, QWebPage::event(), and QWebViewPrivate::page.

| void QWebView::forward | ( | ) | [slot] |
Convenience slot that loads the next document in the list of documents built by navigating links. Does nothing if there is no next document.
It is equivalent to
webkitsnippets/qtwebkit_qwebview_snippet.cpp 5
Definition at line 913 of file qwebview.cpp.
References d, QWebPage::Forward, QWebViewPrivate::page, and QWebPage::triggerAction().

| QWebHistory * QWebView::history | ( | ) | const |
Returns a pointer to the view's history of navigated web pages.
It is equivalent to
webkitsnippets/qtwebkit_qwebview_snippet.cpp 0
Definition at line 522 of file qwebview.cpp.
References QWebPage::history(), and page().

| QIcon QWebView::icon | ( | ) | const |
| void QWebView::iconChanged | ( | ) | [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().
| void QWebView::inputMethodEvent | ( | QInputMethodEvent * | e | ) | [protected, virtual] |
Definition at line 1190 of file qwebview.cpp.
References d, QWebPage::event(), and QWebViewPrivate::page.

| QVariant QWebView::inputMethodQuery | ( | Qt::InputMethodQuery | property | ) | const |
Definition at line 1181 of file qwebview.cpp.
References d, QWebPage::inputMethodQuery(), and QWebViewPrivate::page.

| bool QWebView::isModified | ( | ) | const |
Definition at line 642 of file qwebview.cpp.
References d, QWebPage::isModified(), and QWebViewPrivate::page.

| void QWebView::keyPressEvent | ( | QKeyEvent * | ev | ) | [protected, virtual] |
Definition at line 1092 of file qwebview.cpp.
References d, QWebPage::event(), and QWebViewPrivate::page.

| void QWebView::keyReleaseEvent | ( | QKeyEvent * | ev | ) | [protected, virtual] |
Definition at line 1102 of file qwebview.cpp.
References d, QWebPage::event(), and QWebViewPrivate::page.

| void QWebView::linkClicked | ( | const QUrl & | url | ) | [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.
| 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.
Definition at line 471 of file qwebview.cpp.
References QWebFrame::load(), QWebPage::mainFrame(), and page().

| void QWebView::load | ( | const QUrl & | url | ) |
Loads the specified url and displays it.
Definition at line 454 of file qwebview.cpp.
References QWebFrame::load(), QWebPage::mainFrame(), and page().

| void QWebView::loadFinished | ( | bool | ok | ) | [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.
| void QWebView::loadProgress | ( | int | progress | ) | [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.
The current value is provided by progress and scales from 0 to 100, which is the default range of QProgressBar.
| void QWebView::loadStarted | ( | ) | [signal] |
This signal is emitted when a new load of the page is started.
| void QWebView::mouseDoubleClickEvent | ( | QMouseEvent * | ev | ) | [protected, virtual] |
Definition at line 1034 of file qwebview.cpp.
References d, QWebPage::event(), and QWebViewPrivate::page.

| void QWebView::mouseMoveEvent | ( | QMouseEvent * | ev | ) | [protected, virtual] |
Definition at line 1002 of file qwebview.cpp.
References d, QWebPage::event(), and QWebViewPrivate::page.

| void QWebView::mousePressEvent | ( | QMouseEvent * | ev | ) | [protected, virtual] |
Definition at line 1018 of file qwebview.cpp.
References d, QWebPage::event(), and QWebViewPrivate::page.

| void QWebView::mouseReleaseEvent | ( | QMouseEvent * | ev | ) | [protected, virtual] |
Definition at line 1050 of file qwebview.cpp.
References d, QWebPage::event(), and QWebViewPrivate::page.

| QWebPage * QWebView::page | ( | ) | const |
Returns a pointer to the underlying web page.
Definition at line 382 of file qwebview.cpp.
References d, QWebViewPrivate::page, QWebPage, and setPage().

| QAction * QWebView::pageAction | ( | QWebPage::WebAction | action | ) | const |
Returns a pointer to a QAction that encapsulates the specified web action action.
Definition at line 612 of file qwebview.cpp.
References QWebPage::action(), and page().

| void QWebView::paintEvent | ( | QPaintEvent * | ev | ) | [protected] |
Definition at line 940 of file qwebview.cpp.
References d, fps, FPSRect, FPSTime, frameCount, QWebPage::mainFrame(), QWebViewPrivate::page, QWebFrame::render(), QWebViewPrivate::renderHints, and showFPS.

| void QWebView::print | ( | QPrinter * | printer | ) | const [slot] |
Prints the main frame to the given printer.
Definition at line 865 of file qwebview.cpp.
References QWebPage::mainFrame(), page(), and QWebFrame::print().

| void QWebView::reload | ( | ) | [slot] |
Reloads the current document.
Definition at line 924 of file qwebview.cpp.
References d, QWebViewPrivate::page, QWebPage::Reload, and QWebPage::triggerAction().

| QPainter::RenderHints QWebView::renderHints | ( | ) | const |
| void QWebView::resizeEvent | ( | QResizeEvent * | e | ) | [protected] |
Definition at line 932 of file qwebview.cpp.
References d, QWebViewPrivate::page, and QWebPage::setViewportSize().

| QString QWebView::selectedText | ( | ) | const |
| void QWebView::selectionChanged | ( | ) | [signal] |
This signal is emitted whenever the selection changes.
| 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. If the 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.
The data is loaded immediately; external objects are loaded asynchronously.
Definition at line 510 of file qwebview.cpp.
References QWebPage::mainFrame(), page(), and QWebFrame::setContent().

| void QWebView::setHtml | ( | const QString & | html, | |
| const QUrl & | baseUrl = QUrl() | |||
| ) |
Sets the content of the web view to the specified html.
External objects such as stylesheets or images referenced in the HTML document are located relative to baseUrl.
The 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.
Definition at line 494 of file qwebview.cpp.
References QWebPage::mainFrame(), page(), and QWebFrame::setHtml().

| void QWebView::setPage | ( | QWebPage * | page | ) |
Makes page the new web page of the web view.
The parent QObject of the provided page remains the owner of the object. If the current document is a child of the web view, it will be deleted.
Definition at line 400 of file qwebview.cpp.
References QWebPagePrivate::client, QWebPage::d, d, iconChanged(), linkClicked(), loadFinished(), loadProgress(), loadStarted(), QWebPage::mainFrame(), QWebPagePrivate::page, QWebViewPrivate::page, QWebPage::setPalette(), QWebPage::setView(), statusBarMessage(), titleChanged(), and urlChanged().

| void QWebView::setRenderHint | ( | QPainter::RenderHint | hint, | |
| bool | enabled = true | |||
| ) |
Definition at line 774 of file qwebview.cpp.
References d, and QWebViewPrivate::renderHints.
| void QWebView::setRenderHints | ( | QPainter::RenderHints | hints | ) |
Definition at line 759 of file qwebview.cpp.
References d, and QWebViewPrivate::renderHints.
| void QWebView::setShowFPS | ( | bool | enabled = true |
) | [inline] |
Definition at line 117 of file qwebview.h.
| void QWebView::setTextSizeMultiplier | ( | qreal | factor | ) |
Sets the value of the multiplier used to scale the text in a Web page to the factor specified.
Definition at line 714 of file qwebview.cpp.
References QWebPage::mainFrame(), page(), and QWebFrame::setTextSizeMultiplier().

| QWebSettings * QWebView::settings | ( | ) | const |
Returns a pointer to the view/page specific settings object.
It is equivalent to
webkitsnippets/qtwebkit_qwebview_snippet.cpp 1
Definition at line 536 of file qwebview.cpp.
References page(), and QWebPage::settings().

| void QWebView::setUrl | ( | const QUrl & | url | ) |
Definition at line 567 of file qwebview.cpp.
References QWebPage::mainFrame(), page(), and QWebFrame::setUrl().

| void QWebView::setZoomFactor | ( | qreal | factor | ) |
Definition at line 686 of file qwebview.cpp.
References QWebPage::mainFrame(), page(), and QWebFrame::setZoomFactor().

| QSize QWebView::sizeHint | ( | ) | const |
Definition at line 675 of file qwebview.cpp.
| void QWebView::statusBarMessage | ( | const QString & | text | ) | [signal] |
This signal is emitted when the status bar text is changed by the page.
| void QWebView::stop | ( | ) | [slot] |
Convenience slot that stops loading the document.
It is equivalent to
webkitsnippets/qtwebkit_qwebview_snippet.cpp 3
Definition at line 881 of file qwebview.cpp.
References d, QWebViewPrivate::page, QWebPage::Stop, and QWebPage::triggerAction().

| qreal QWebView::textSizeMultiplier | ( | ) | const |
| QString QWebView::title | ( | ) | const |
| void QWebView::titleChanged | ( | const QString & | title | ) | [signal] |
This signal is emitted whenever the title of the main frame changes.
| void QWebView::triggerPageAction | ( | QWebPage::WebAction | action, | |
| bool | checked = false | |||
| ) |
Triggers the specified action. If it is a checkable action the specified checked state is assumed.
The following example triggers the copy action and therefore copies any selected text to the clipboard.
webkitsnippets/qtwebkit_qwebview_snippet.cpp 2
Definition at line 628 of file qwebview.cpp.
References page(), and QWebPage::triggerAction().

| QUrl QWebView::url | ( | ) | const |
| void QWebView::urlChanged | ( | const QUrl & | url | ) | [signal] |
| void QWebView::wheelEvent | ( | QWheelEvent * | ev | ) | [protected, virtual] |
Definition at line 1080 of file qwebview.cpp.
References d, QWebPage::event(), and QWebViewPrivate::page.

| qreal QWebView::zoomFactor | ( | ) | const |
friend class QWebPage [friend] |
Definition at line 178 of file qwebview.h.
QWebViewPrivate* QWebView::d [private] |
Definition at line 179 of file qwebview.h.
qreal QWebView::fps [private] |
Definition at line 183 of file qwebview.h.
QRect QWebView::FPSRect [private] |
Definition at line 186 of file qwebview.h.
QTime QWebView::FPSTime [private] |
Definition at line 184 of file qwebview.h.
int QWebView::frameCount [private] |
Definition at line 182 of file qwebview.h.
bool QWebView::showFPS [private] |
Definition at line 185 of file qwebview.h.
QIcon QWebView::icon [read] |
the icon associated with the web page currently viewed
By default, this property contains a null icon.
Definition at line 55 of file qwebview.h.
QWebView::modified [read] |
whether the document was modified by the user
Parts of HTML documents can be editable for example through the {contenteditable} attribute on HTML elements.
By default, this property is false.
Definition at line 57 of file qwebview.h.
QPainter::RenderHints QWebView::renderHints [read, write] |
the default render hints for the view
QPainter::TextAntialiasing is enabled by default.
Definition at line 62 of file qwebview.h.
QString QWebView::selectedText [read] |
the text currently selected
By default, this property contains an empty string.
Definition at line 56 of file qwebview.h.
qreal QWebView::textSizeMultiplier [read, write] |
the scaling factor for all text in the frame
Use setZoomFactor instead, in combination with the ZoomTextOnly attribute in QWebSettings.
By default, this property contains a value of 1.0.
Returns the value of the multiplier used to scale the text in a Web page.
Definition at line 59 of file qwebview.h.
QString QWebView::title [read] |
the title of the web page currently viewed
By default, this property contains an empty string.
Definition at line 53 of file qwebview.h.
QUrl QWebView::url [read, write] |
the url of the web page currently viewed
Setting this property clears the view and loads the URL.
By default, this property contains an empty, invalid URL.
Definition at line 54 of file qwebview.h.
qreal QWebView::zoomFactor [read, write] |
1.6.2-20100208