|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QWidget
com.trolltech.qt.webkit.QWebView
public class QWebView
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.
The image below shows QWebView previewed in Qt Designer with the Nokia website.
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(new QUrl("http://www.trolltech.com/")); view.show();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 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
using the print()
function. This function is marked as a slot and can be conveniently connected to QPrintPreviewDialog
's 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.Elements of QWebView
QWebView consists of other objects such as QWebFrame
and QWebPage
. The flowchart below shows these elements are related.
QWebPage
and QWebFrame
, without using QWebView, if you do not require QWidget
attributes. Nevertheless, QtWebKit depends on QtGui, so you should use a QApplication
instead of QCoreApplication
.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget |
---|
QWidget.RenderFlag, QWidget.RenderFlags |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary | |
---|---|
QSignalEmitter.Signal0 |
iconChanged
This signal is emitted whenever the icon of the page is loaded or changes. |
QSignalEmitter.Signal1 |
linkClicked
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
loadFinished
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
loadProgress
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal0 |
loadStarted
This signal is emitted when a new load of the page is started. |
QSignalEmitter.Signal0 |
selectionChanged
This signal is emitted whenever the selection changes. |
QSignalEmitter.Signal1 |
statusBarMessage
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
titleChanged
This signal takes 1 generic argument(s). |
QSignalEmitter.Signal1 |
urlChanged
This signal takes 1 generic argument(s). |
Fields inherited from class com.trolltech.qt.gui.QWidget |
---|
customContextMenuRequested |
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QWebView()
Constructs an empty QWebView with parent parent. |
|
QWebView(QWidget parent)
Constructs an empty QWebView with parent parent. |
Method Summary | |
---|---|
void |
back()
Convenience slot that loads the previous document in the list of documents built by navigating links. |
protected QWebView |
createWindow(QWebPage.WebWindowType type)
This function is called whenever WebKit wants to create a new window of the given type, for example as a result of a JavaScript request to open a document in a new window. |
boolean |
findText(java.lang.String subString)
Finds the next occurrence of the string, subString, in the page, using the given options. |
boolean |
findText(java.lang.String subString,
QWebPage.FindFlag[] options)
|
boolean |
findText(java.lang.String subString,
QWebPage.FindFlags options)
Finds the next occurrence of the string, subString, in the page, using the given options. |
void |
forward()
Convenience slot that loads the next document in the list of documents built by navigating links. |
QWebHistory |
history()
Returns a pointer to the view's history of navigated web pages. |
QIcon |
icon()
This property holds the icon associated with the web page currently viewed. |
boolean |
isModified()
This property holds whether the document was modified by the user. |
void |
load(QNetworkRequest request)
Loads a network request, request, using the method specified in operation. |
void |
load(QNetworkRequest request,
QNetworkAccessManager.Operation operation)
Loads a network request, request, using the method specified in operation. |
void |
load(QNetworkRequest request,
QNetworkAccessManager.Operation operation,
QByteArray body)
Loads a network request, request, using the method specified in operation. |
void |
load(QUrl url)
Loads the specified url and displays it. |
QWebPage |
page()
Returns a pointer to the underlying web page. |
QAction |
pageAction(QWebPage.WebAction action)
Returns a pointer to a QAction that encapsulates the specified web action action. |
void |
print(QPrinter printer)
Prints the main frame to the given printer. |
void |
reload()
Reloads the current document. |
java.lang.String |
selectedText()
This property holds the text currently selected. |
void |
setContent(QByteArray data)
Sets the content of the web view to the specified content data. |
void |
setContent(QByteArray data,
java.lang.String mimeType)
Sets the content of the web view to the specified content data. |
void |
setContent(QByteArray data,
java.lang.String mimeType,
QUrl baseUrl)
Sets the content of the web view to the specified content data. |
void |
setHtml(java.lang.String html)
Sets the content of the web view to the specified html. |
void |
setHtml(java.lang.String html,
QUrl baseUrl)
Sets the content of the web view to the specified html. |
void |
setPage(QWebPage page)
Makes page the new web page of the web view. |
void |
setTextSizeMultiplier(double factor)
This property holds the scaling factor for all text in the frame. |
QWebSettings |
settings()
Returns a pointer to the view/page specific settings object. |
void |
setUrl(QUrl url)
This property holds the url of the web page currently viewed. |
void |
stop()
Convenience slot that stops loading the document. |
double |
textSizeMultiplier()
This property holds the scaling factor for all text in the frame. |
java.lang.String |
title()
This property holds the title of the web page currently viewed. |
void |
triggerPageAction(QWebPage.WebAction action)
Triggers the specified action. |
void |
triggerPageAction(QWebPage.WebAction action,
boolean checked)
Triggers the specified action. |
QUrl |
url()
This property holds the url of the web page currently viewed. |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Field Detail |
---|
public final QSignalEmitter.Signal0 iconChanged
icon()
.
public final QSignalEmitter.Signal1 linkClicked
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.core.QUrl(named: 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()
.
public final QSignalEmitter.Signal1 loadFinished
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Boolean(named: ok)>:
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()
.
public final QSignalEmitter.Signal1 loadProgress
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.Integer(named: 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.
The current value is provided by progress and scales from 0 to 100, which is the default range of QProgressBar
.
loadStarted()
, and loadFinished()
.
public final QSignalEmitter.Signal0 loadStarted
loadProgress()
, and loadFinished()
.
public final QSignalEmitter.Signal0 selectionChanged
selectedText()
.
public final QSignalEmitter.Signal1 statusBarMessage
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.String(named: text)>:
This signal is emitted when the statusbar text is changed by the page.
public final QSignalEmitter.Signal1 titleChanged
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <java.lang.String(named: title)>:
This signal is emitted whenever the title of the main frame changes.
title()
.
public final QSignalEmitter.Signal1 urlChanged
This signal takes 1 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.core.QUrl(named: url)>:
This signal is emitted when the url of the view changes.
url()
, and load()
.
Constructor Detail |
---|
public QWebView()
load()
.
public QWebView(QWidget parent)
load()
.
Method Detail |
---|
public final void back()
It is equivalent to
view.page().triggerAction(QWebPage.WebAction.GoBack);
forward()
, and pageAction()
.
public final boolean findText(java.lang.String subString, QWebPage.FindFlag[] options)
public final boolean findText(java.lang.String subString)
selectedText()
, and selectionChanged()
.
public final boolean findText(java.lang.String subString, QWebPage.FindFlags options)
selectedText()
, and selectionChanged()
.
public final void forward()
It is equivalent to
view.page().triggerAction(QWebPage.WebAction.GoForward);
back()
, and pageAction()
.
public final QWebHistory history()
It is equivalent to
view.page().history();
public final QIcon icon()
iconChanged()
, and QWebSettings::iconForUrl()
.
public final boolean isModified()
By default, this property is false.
public final void load(QNetworkRequest request, QNetworkAccessManager.Operation operation)
body is optional and is only used for POST operations.
Note: The view remains the same until enough data has arrived to display the new url.
url()
, and urlChanged()
.
public final void load(QNetworkRequest request)
body is optional and is only used for POST operations.
Note: The view remains the same until enough data has arrived to display the new url.
url()
, and urlChanged()
.
public final void load(QNetworkRequest request, QNetworkAccessManager.Operation operation, QByteArray body)
body is optional and is only used for POST operations.
Note: The view remains the same until enough data has arrived to display the new url.
url()
, and urlChanged()
.
public final void load(QUrl url)
Note: The view remains the same until enough data has arrived to display the new url.
setUrl()
, url()
, and urlChanged()
.
public final QWebPage page()
setPage()
.
public final QAction pageAction(QWebPage.WebAction action)
QAction
that encapsulates the specified web action action.
public final void print(QPrinter printer)
QWebFrame::print()
, and QPrintPreviewDialog
.
public final void reload()
stop()
, pageAction()
, and loadStarted()
.
public final java.lang.String selectedText()
findText()
, and selectionChanged()
.
public final void setContent(QByteArray data, java.lang.String mimeType)
External objects referenced in the content are located relative to baseUrl.
load()
, setHtml()
, and QWebFrame::toHtml()
.
public final void setContent(QByteArray data)
External objects referenced in the content are located relative to baseUrl.
load()
, setHtml()
, and QWebFrame::toHtml()
.
public final void setContent(QByteArray data, java.lang.String mimeType, QUrl baseUrl)
External objects referenced in the content are located relative to baseUrl.
load()
, setHtml()
, and QWebFrame::toHtml()
.
public final void setHtml(java.lang.String html)
External objects referenced in the HTML document are located relative to baseUrl.
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.
load()
, setContent()
, and QWebFrame::toHtml()
.
public final void setHtml(java.lang.String html, QUrl baseUrl)
External objects referenced in the HTML document are located relative to baseUrl.
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.
load()
, setContent()
, and QWebFrame::toHtml()
.
public final void setPage(QWebPage page)
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.
page()
.
public final void setTextSizeMultiplier(double factor)
public final void setUrl(QUrl url)
By default, this property contains an empty, invalid URL.
load()
, and urlChanged()
.
public final QWebSettings settings()
It is equivalent to
view.page().settings();
QWebSettings::globalSettings()
.
public final void stop()
It is equivalent to
view.page().triggerAction(QWebPage.WebAction.Stop);
reload()
, pageAction()
, and loadFinished()
.
public final double textSizeMultiplier()
public final java.lang.String title()
titleChanged()
.
public final void triggerPageAction(QWebPage.WebAction action)
The following example triggers the copy action and therefore copies any selected text to the clipboard.
view.triggerAction(QWebPage.WebAction.Copy);
pageAction()
.
public final void triggerPageAction(QWebPage.WebAction action, boolean checked)
The following example triggers the copy action and therefore copies any selected text to the clipboard.
view.triggerAction(QWebPage.WebAction.Copy);
pageAction()
.
public final QUrl url()
By default, this property contains an empty, invalid URL.
load()
, and urlChanged()
.
protected QWebView createWindow(QWebPage.WebWindowType type)
QWebPage::createWindow()
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |