Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QWebPage Class

TheQWebPage class provides an object to view and edit web documents.More...

Header:#include <QWebPage>
Since: Qt 4.4
Inherits:QObject

Public Types

classChooseMultipleFilesExtensionOption
classChooseMultipleFilesExtensionReturn
classErrorPageExtensionOption
classErrorPageExtensionReturn
classExtensionOption
classExtensionReturn
classViewportAttributes
enumErrorDomain { QtNetwork, Http, WebKit }
enumExtension { ChooseMultipleFilesExtension, ErrorPageExtension }
enumFeature { Notifications, Geolocation }
enumFindFlag { FindBackward, FindCaseSensitively, FindWrapsAroundDocument, HighlightAllOccurrences }
flagsFindFlags
enumLinkDelegationPolicy { DontDelegateLinks, DelegateExternalLinks, DelegateAllLinks }
enumNavigationType { NavigationTypeLinkClicked, NavigationTypeFormSubmitted, NavigationTypeBackOrForward, NavigationTypeReload, NavigationTypeFormResubmitted, NavigationTypeOther }
enumPermissionPolicy { PermissionUnknown, PermissionGrantedByUser, PermissionDeniedByUser }
enumWebAction { NoWebAction, OpenLink, OpenLinkInNewWindow, OpenFrameInNewWindow, ..., AlignRight }
enumWebWindowType { WebBrowserWindow, WebModalDialog }

Properties

Public Functions

QWebPage(QObject * parent = 0)
~QWebPage()
QAction *action(WebAction action) const
quint64bytesReceived() const
QMenu *createStandardContextMenu()
QWebFrame *currentFrame() const
virtual boolextension(Extension extension, const ExtensionOption * option = 0, ExtensionReturn * output = 0)
boolfindText(const QString & subString, FindFlags options = 0)
boolfocusNextPrevChild(bool next)
boolforwardUnsupportedContent() const
QWebFrame *frameAt(const QPoint & pos) const
boolhasSelection() const
QWebHistory *history() const
QVariantinputMethodQuery(Qt::InputMethodQuery property) const
boolisContentEditable() const
boolisModified() const
LinkDelegationPolicylinkDelegationPolicy() const
QWebFrame *mainFrame() const
QNetworkAccessManager *networkAccessManager() const
QPalettepalette() const
QWebPluginFactory *pluginFactory() const
QSizepreferredContentsSize() const
QStringselectedHtml() const
QStringselectedText() const
voidsetActualVisibleContentRect(const QRect & rect) const
voidsetContentEditable(bool editable)
voidsetFeaturePermission(QWebFrame * frame, Feature feature, PermissionPolicy policy)
voidsetForwardUnsupportedContent(bool forward)
voidsetLinkDelegationPolicy(LinkDelegationPolicy policy)
voidsetNetworkAccessManager(QNetworkAccessManager * manager)
voidsetPalette(const QPalette & palette)
voidsetPluginFactory(QWebPluginFactory * factory)
voidsetPreferredContentsSize(const QSize & size) const
voidsetView(QWidget * view)
voidsetViewportSize(const QSize & size) const
QWebSettings *settings() const
QStringListsupportedContentTypes() const
boolsupportsContentType(const QString & mimeType) const
virtual boolsupportsExtension(Extension extension) const
boolswallowContextMenuEvent(QContextMenuEvent * event)
quint64totalBytes() const
virtual voidtriggerAction(WebAction action, bool checked = false)
QUndoStack *undoStack() const
voidupdatePositionDependentActions(const QPoint & pos)
QWidget *view() const
ViewportAttributesviewportAttributesForSize(const QSize & availableSize) const
QSizeviewportSize() const

Reimplemented Public Functions

virtual boolevent(QEvent * ev)
  • 29 public functions inherited fromQObject

Public Slots

  • 1 public slot inherited fromQObject

Signals

voidapplicationCacheQuotaExceeded(QWebSecurityOrigin * origin, quint64 defaultOriginQuota)
voidcontentsChanged()
voiddatabaseQuotaExceeded(QWebFrame * frame, QString databaseName)
voiddownloadRequested(const QNetworkRequest & request)
voidfeaturePermissionRequestCanceled(QWebFrame * frame, QWebPage::Feature feature)
voidfeaturePermissionRequested(QWebFrame * frame, QWebPage::Feature feature)
voidframeCreated(QWebFrame * frame)
voidgeometryChangeRequested(const QRect & geom)
voidlinkClicked(const QUrl & url)
voidlinkHovered(const QString & link, const QString & title, const QString & textContent)
voidloadFinished(bool ok)
voidloadProgress(int progress)
voidloadStarted()
voidmenuBarVisibilityChangeRequested(bool visible)
voidmicroFocusChanged()
voidprintRequested(QWebFrame * frame)
voidrepaintRequested(const QRect & dirtyRect)
voidrestoreFrameStateRequested(QWebFrame * frame)
voidsaveFrameStateRequested(QWebFrame * frame, QWebHistoryItem * item)
voidscrollRequested(int dx, int dy, const QRect & rectToScroll)
voidselectionChanged()
voidstatusBarMessage(const QString & text)
voidstatusBarVisibilityChangeRequested(bool visible)
voidtoolBarVisibilityChangeRequested(bool visible)
voidunsupportedContent(QNetworkReply * reply)
voidviewportChangeRequested()
voidwindowCloseRequested()

Protected Functions

virtual boolacceptNavigationRequest(QWebFrame * frame, const QNetworkRequest & request, NavigationType type)
virtual QStringchooseFile(QWebFrame * parentFrame, const QString & suggestedFile)
virtual QObject *createPlugin(const QString & classid, const QUrl & url, const QStringList & paramNames, const QStringList & paramValues)
virtual QWebPage *createWindow(WebWindowType type)
virtual voidjavaScriptAlert(QWebFrame * frame, const QString & msg)
virtual booljavaScriptConfirm(QWebFrame * frame, const QString & msg)
virtual voidjavaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID)
virtual booljavaScriptPrompt(QWebFrame * frame, const QString & msg, const QString & defaultValue, QString * result)
virtual QStringuserAgentForUrl(const QUrl & url) const
  • 8 protected functions inherited fromQObject

Related Non-Members

Macros

Additional Inherited Members

  • 7 static public members inherited fromQObject

Detailed Description

TheQWebPage class provides an object to view and edit web documents.

QWebPage holds a main frame responsible for web content, settings, the history of navigated links and actions. This class can be used, together withQWebFrame, to provide functionality likeQWebView in a widget-less environment.

QWebPage's API is very similar toQWebView, as you are still provided with common functions likeaction() (known aspageAction() inQWebView),triggerAction(),findText() andsettings(). MoreQWebView-like functions can be found in the main frame ofQWebPage, obtained via themainFrame() function. For example, theload(),setUrl() andsetHtml() functions forQWebPage can be accessed usingQWebFrame.

TheloadStarted() signal is emitted when the page begins to load.TheloadProgress() signal, on the other hand, is emitted whenever an element of the web page completes loading, such as an embedded image, a script, etc. Finally, theloadFinished() signal is emitted when the page contents are loaded completely, independent of script execution or page rendering. Its argument, either true or false, indicates whether or not the load operation succeeded.

Using QWebPage in a Widget-less Environment

Before you begin painting aQWebPage object, you need to set the size of the viewport by callingsetViewportSize(). Then, you invoke the main frame's render function (QWebFrame::render()). An example of this is shown in the code snippet below.

Suppose we have aThumbnail class as follows:

class Thumbnailer :publicQObject{    Q_OBJECTpublic:    Thumbnailer(constQUrl&url);signals:void finished();privateslots:void render();private:QWebPage page;};

TheThumbnail's constructor takes in aurl. We connect ourQWebPage object'sloadFinished() signal to our private slot,render().

Thumbnailer::Thumbnailer(constQUrl&url){    page.mainFrame()->load(url);    connect(&page, SIGNAL(loadFinished(bool)),this, SLOT(render()));}

Therender() function shows how we can paint a thumbnail using aQWebPage object.

void Thumbnailer::render(){    page.setViewportSize(page.mainFrame()->contentsSize());QImage image(page.viewportSize(),QImage::Format_ARGB32);QPainter painter(&image);    page.mainFrame()->render(&painter);    painter.end();QImage thumbnail= image.scaled(400,400);    thumbnail.save("thumbnail.png");emit finished();}

We begin by setting theviewportSize and then we instantiate aQImage object,image, with the same size as ourviewportSize. This image is then sent as a parameter topainter. Next, we render the contents of the main frame and its subframes intopainter. Finally, we save the scaled image.

See alsoQWebFrame.

Member Type Documentation

enum QWebPage::ErrorDomain

This enum describes the domain of anErrorPageExtensionOption object (i.e. the layer in which the error occurred).

ConstantValueDescription
QWebPage::QtNetwork0The error occurred in the QtNetwork layer; the error code is of typeQNetworkReply::NetworkError.
QWebPage::Http1The error occurred in the HTTP layer; the error code is a HTTP status code (seeQNetworkRequest::HttpStatusCodeAttribute).
QWebPage::WebKit2The error is an internalWebKit error.

This enum was introduced or modified in Qt 4.6.

enum QWebPage::Extension

This enum describes the types of extensions that the page can support. Before using these extensions, you should verify that the extension is supported by callingsupportsExtension().

ConstantValueDescription
QWebPage::ChooseMultipleFilesExtension0Whether the web page supports multiple file selection. This extension is invoked when the web content requests one or more file names, for example as a result of the user clicking on a "file upload" button in a HTML form where multiple file selection is allowed.
QWebPage::ErrorPageExtension1Whether the web page can provide an error page when loading fails. (introduced in Qt 4.6)

See alsoChooseMultipleFilesExtensionOption,ChooseMultipleFilesExtensionReturn,ErrorPageExtensionOption, andErrorPageExtensionReturn.

enum QWebPage::Feature

enum QWebPage::FindFlag
flags QWebPage::FindFlags

This enum describes the options available to thefindText() function. The options can be OR-ed together from the following list:

ConstantValueDescription
QWebPage::FindBackward1Searches backwards instead of forwards.
QWebPage::FindCaseSensitively2By defaultfindText() works case insensitive. Specifying this option changes the behaviour to a case sensitive find operation.
QWebPage::FindWrapsAroundDocument4MakesfindText() restart from the beginning of the document if the end was reached and the text was not found.
QWebPage::HighlightAllOccurrences8Highlights all existing occurrences of a specific string. (This value was introduced in 4.6.)

The FindFlags type is a typedef forQFlags<FindFlag>. It stores an OR combination of FindFlag values.

enum QWebPage::LinkDelegationPolicy

This enum defines the delegation policies a webpage can have when activating links and emitting thelinkClicked() signal.

ConstantValueDescription
QWebPage::DontDelegateLinks0No links are delegated. Instead,QWebPage tries to handle them all.
QWebPage::DelegateExternalLinks1When activating links that point to documents not stored on the local filesystem or an equivalent - such as the Qt resource system - thenlinkClicked() is emitted.
QWebPage::DelegateAllLinks2Whenever a link is activated thelinkClicked() signal is emitted.

See alsoQWebPage::linkDelegationPolicy.

enum QWebPage::NavigationType

This enum describes the types of navigation available when browsing through hyperlinked documents.

ConstantValueDescription
QWebPage::NavigationTypeLinkClicked0The user clicked on a link or pressed return on a focused link.
QWebPage::NavigationTypeFormSubmitted1The user activated a submit button for an HTML form.
QWebPage::NavigationTypeBackOrForward2Navigation to a previously shown document in the back or forward history is requested.
QWebPage::NavigationTypeReload3The user activated the reload action.
QWebPage::NavigationTypeFormResubmitted4An HTML form was submitted a second time.
QWebPage::NavigationTypeOther5A navigation to another document using a method not listed above.

See alsoacceptNavigationRequest().

enum QWebPage::PermissionPolicy

enum QWebPage::WebAction

This enum describes the types of action which can be performed on the web page.

Actions only have an effect when they are applicable. The availability of actions can be be determined by checkingisEnabled() on the action returned byaction().

One method of enabling the text editing, cursor movement, and text selection actions is by settingcontentEditable to true.

ConstantValueDescription
QWebPage::NoWebAction-1No action is triggered.
QWebPage::OpenLink0Open the current link.
QWebPage::OpenLinkInNewWindow1Open the current link in a new window.
QWebPage::OpenFrameInNewWindow2Replicate the current frame in a new window.
QWebPage::DownloadLinkToDisk3Download the current link to the disk.
QWebPage::CopyLinkToClipboard4Copy the current link to the clipboard.
QWebPage::OpenImageInNewWindow5Open the highlighted image in a new window.
QWebPage::DownloadImageToDisk6Download the highlighted image to the disk.
QWebPage::CopyImageToClipboard7Copy the highlighted image to the clipboard.
QWebPage::CopyImageUrlToClipboard68Copy the highlighted image's URL to the clipboard.
QWebPage::Back8Navigate back in the history of navigated links.
QWebPage::Forward9Navigate forward in the history of navigated links.
QWebPage::Stop10Stop loading the current page.
QWebPage::StopScheduledPageRefresh67Stop all pending page refresh/redirect requests.
QWebPage::Reload11Reload the current page.
QWebPage::ReloadAndBypassCache53Reload the current page, but do not use any local cache. (Added in Qt 4.6)
QWebPage::Cut12Cut the content currently selected into the clipboard.
QWebPage::Copy13Copy the content currently selected into the clipboard.
QWebPage::Paste14Paste content from the clipboard.
QWebPage::Undo15Undo the last editing action.
QWebPage::Redo16Redo the last editing action.
QWebPage::MoveToNextChar17Move the cursor to the next character.
QWebPage::MoveToPreviousChar18Move the cursor to the previous character.
QWebPage::MoveToNextWord19Move the cursor to the next word.
QWebPage::MoveToPreviousWord20Move the cursor to the previous word.
QWebPage::MoveToNextLine21Move the cursor to the next line.
QWebPage::MoveToPreviousLine22Move the cursor to the previous line.
QWebPage::MoveToStartOfLine23Move the cursor to the start of the line.
QWebPage::MoveToEndOfLine24Move the cursor to the end of the line.
QWebPage::MoveToStartOfBlock25Move the cursor to the start of the block.
QWebPage::MoveToEndOfBlock26Move the cursor to the end of the block.
QWebPage::MoveToStartOfDocument27Move the cursor to the start of the document.
QWebPage::MoveToEndOfDocument28Move the cursor to the end of the document.
QWebPage::SelectNextChar29Select to the next character.
QWebPage::SelectPreviousChar30Select to the previous character.
QWebPage::SelectNextWord31Select to the next word.
QWebPage::SelectPreviousWord32Select to the previous word.
QWebPage::SelectNextLine33Select to the next line.
QWebPage::SelectPreviousLine34Select to the previous line.
QWebPage::SelectStartOfLine35Select to the start of the line.
QWebPage::SelectEndOfLine36Select to the end of the line.
QWebPage::SelectStartOfBlock37Select to the start of the block.
QWebPage::SelectEndOfBlock38Select to the end of the block.
QWebPage::SelectStartOfDocument39Select to the start of the document.
QWebPage::SelectEndOfDocument40Select to the end of the document.
QWebPage::DeleteStartOfWord41Delete to the start of the word.
QWebPage::DeleteEndOfWord42Delete to the end of the word.
QWebPage::SetTextDirectionDefault43Set the text direction to the default direction.
QWebPage::SetTextDirectionLeftToRight44Set the text direction to left-to-right.
QWebPage::SetTextDirectionRightToLeft45Set the text direction to right-to-left.
QWebPage::ToggleBold46Toggle the formatting between bold and normal weight.
QWebPage::ToggleItalic47Toggle the formatting between italic and normal style.
QWebPage::ToggleUnderline48Toggle underlining.
QWebPage::InspectElement49Show the Web Inspector with the currently highlighted HTML element.
QWebPage::InsertParagraphSeparator50Insert a new paragraph.
QWebPage::InsertLineSeparator51Insert a new line.
QWebPage::SelectAll52Selects all content.
QWebPage::PasteAndMatchStyle54Paste content from the clipboard with current style.
QWebPage::RemoveFormat55Removes formatting and style.
QWebPage::ToggleStrikethrough56Toggle the formatting between strikethrough and normal style.
QWebPage::ToggleSubscript57Toggle the formatting between subscript and baseline.
QWebPage::ToggleSuperscript58Toggle the formatting between supercript and baseline.
QWebPage::InsertUnorderedList59Toggles the selection between an ordered list and a normal block.
QWebPage::InsertOrderedList60Toggles the selection between an ordered list and a normal block.
QWebPage::Indent61Increases the indentation of the currently selected format block by one increment.
QWebPage::Outdent62Decreases the indentation of the currently selected format block by one increment.
QWebPage::AlignCenter63Applies center alignment to content.
QWebPage::AlignJustified64Applies full justification to content.
QWebPage::AlignLeft65Applies left justification to content.
QWebPage::AlignRight66Applies right justification to content.

enum QWebPage::WebWindowType

This enum describes the types of window that can be created by thecreateWindow() function.

ConstantValueDescription
QWebPage::WebBrowserWindow0The window is a regular web browser window.
QWebPage::WebModalDialog1The window acts as modal dialog.

Property Documentation

contentEditable :bool

This property holds whether the content in this QWebPage is editable or not.

If this property is enabled the contents of the page can be edited by the user through a visible cursor. If disabled (the default) only HTML elements in the web page with theircontenteditable attribute set are editable.

This property was introduced in Qt 4.5.

Access functions:

boolisContentEditable() const
voidsetContentEditable(bool editable)

See alsomodified,contentsChanged(), andWebAction.

forwardUnsupportedContent :bool

This property holds whether QWebPage should forward unsupported content.

If enabled, theunsupportedContent() signal is emitted with a network reply that can be used to read the content.

If disabled, the download of such content is aborted immediately.

By default unsupported content is not forwarded.

Access functions:

boolforwardUnsupportedContent() const
voidsetForwardUnsupportedContent(bool forward)

hasSelection : constbool

This property holds whether this page contains selected content or not.

Access functions:

boolhasSelection() const

See alsoselectionChanged().

linkDelegationPolicy :LinkDelegationPolicy

This property holds how QWebPage should delegate the handling of links through the linkClicked() signal.

The default is to delegate no links.

Access functions:

LinkDelegationPolicylinkDelegationPolicy() const
voidsetLinkDelegationPolicy(LinkDelegationPolicy policy)

modified : constbool

This property holds whether the page contains unsubmitted form data, or the contents have been changed.

By default, this property is false.

Access functions:

boolisModified() const

See alsocontentsChanged(),contentEditable, andundoStack().

palette :QPalette

This property holds the page's palette.

The base brush of the palette is used to draw the background of the main frame.

By default, this property contains the application's default palette.

Access functions:

QPalettepalette() const
voidsetPalette(const QPalette & palette)

preferredContentsSize :QSize

This property holds a custom size used for laying out the page contents.

By default all pages are laid out using the viewport of the page as the base.

As pages mostly are designed for desktop usage, they often do not layout properly on small devices as the contents require a certain view width. For this reason it is common to use a different layout size and then scale the contents to fit within the actual view.

If this property is set to a valid size, this size is used for all layout needs instead of the size of the viewport.

Setting an invalid size, makes the page fall back to using the viewport size for layout.

This property was introduced in Qt 4.6.

Access functions:

QSizepreferredContentsSize() const
voidsetPreferredContentsSize(const QSize & size) const

See alsoviewportSize.

selectedHtml : constQString

This property holds the HTML currently selected.

By default, this property contains an empty string.

This property was introduced in Qt 4.8.

Access functions:

QStringselectedHtml() const

See alsoselectionChanged() andselectedText().

selectedText : constQString

This property holds the text currently selected.

By default, this property contains an empty string.

Access functions:

QStringselectedText() const

See alsoselectionChanged() andselectedHtml().

viewportSize :QSize

This property holds the size of the viewport.

The size affects for example the visibility of scrollbars if the document is larger than the viewport.

By default, for a newly-created Web page, this property contains a size with zero width and height.

Access functions:

QSizeviewportSize() const
voidsetViewportSize(const QSize & size) const

See alsoQWebFrame::render() andpreferredContentsSize.

Member Function Documentation

QWebPage::QWebPage(QObject * parent = 0)

Constructs an emptyQWebPage with parentparent.

QWebPage::~QWebPage()

Destroys the web page.

[virtual protected]bool QWebPage::acceptNavigationRequest(QWebFrame * frame, constQNetworkRequest & request,NavigationType type)

This function is called wheneverWebKit requests to navigateframe to the resource specified byrequest by means of the specified navigation typetype.

Ifframe is a null pointer then navigation to a new window is requested. If the request is acceptedcreateWindow() will be called.

The default implementation interprets the page'slinkDelegationPolicy and emitslinkClicked accordingly or returns true to letQWebPage handle the navigation itself.

See alsocreateWindow().

QAction * QWebPage::action(WebAction action) const

Returns aQAction for the specifiedWebActionaction.

The action is owned by theQWebPage but you can customize the look by changing its properties.

QWebPage also takes care of implementing the action, so that upon triggering the corresponding action is performed on the page.

See alsotriggerAction().

[signal]void QWebPage::applicationCacheQuotaExceeded(QWebSecurityOrigin * origin,quint64 defaultOriginQuota)

This signal is emitted whenever the web site is asking to store data to the application cache database databaseName and the quota allocated to that web site is exceeded.

quint64 QWebPage::bytesReceived() const

Returns the number of bytes that were received from the network to render the current page.

See alsototalBytes() andloadProgress().

[virtual protected]QString QWebPage::chooseFile(QWebFrame * parentFrame, constQString & suggestedFile)

This function is called when the web content requests a file name, for example as a result of the user clicking on a "file upload" button in a HTML form.

A suggested filename may be provided insuggestedFile. The frame originating the request is provided asparentFrame.

See alsoChooseMultipleFilesExtension.

[signal]void QWebPage::contentsChanged()

This signal is emitted whenever the text in form elements changes as well as other editable content.

This function was introduced in Qt 4.5.

See alsocontentEditable,modified,QWebFrame::toHtml(), andQWebFrame::toPlainText().

[virtual protected]QObject * QWebPage::createPlugin(constQString & classid, constQUrl & url, constQStringList & paramNames, constQStringList & paramValues)

This function is called wheneverWebKit encounters a HTML object element with type "application/x-qt-plugin". It is called regardless of the value ofQWebSettings::PluginsEnabled. Theclassid,url,paramNames andparamValues correspond to the HTML object element attributes and child elements to configure the embeddable object.

QMenu * QWebPage::createStandardContextMenu()

This function creates the standard context menu which is shown when the user clicks on the web page with the right mouse button. It is called from the default contextMenuEvent() handler. The popup menu's ownership is transferred to the caller.

This function was introduced in Qt 4.5.

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

This function is called wheneverWebKit wants to create a new window of the giventype, for example when a JavaScript program requests to open a document in a new window.

If the new window can be created, the new window'sQWebPage is returned; otherwise a null pointer is returned.

If the view associated with the web page is aQWebView object, then the default implementation forwards the request toQWebView's createWindow() function; otherwise it returns a null pointer.

Iftype isWebModalDialog, the application must call setWindowModality(Qt::ApplicationModal) on the new window.

Note:In the cases when the window creation is being triggered by JavaScript, apart from reimplementing this method application must also set the JavaScriptCanOpenWindows attribute ofQWebSettings to true in order for it to get called.

See alsoacceptNavigationRequest() andQWebView::createWindow().

QWebFrame * QWebPage::currentFrame() const

Returns the frame currently active.

See alsomainFrame() andframeCreated().

[signal]void QWebPage::databaseQuotaExceeded(QWebFrame * frame,QString databaseName)

This signal is emitted whenever the web site shown inframe is asking to store data to the databasedatabaseName and the quota allocated to that web site is exceeded.

This function was introduced in Qt 4.5.

See alsoQWebDatabase.

[signal]void QWebPage::downloadRequested(constQNetworkRequest & request)

This signal is emitted when the user decides to download a link. The url of the link as well as additional meta-information is contained inrequest.

See alsounsupportedContent().

[virtual]bool QWebPage::event(QEvent * ev)

Reimplemented fromQObject::event().

[virtual]bool QWebPage::extension(Extension extension, constExtensionOption * option = 0,ExtensionReturn * output = 0)

This virtual function can be reimplemented in aQWebPage subclass to provide support for extensions. Theoption argument is provided as input to the extension; the output results can be stored inoutput.

The behavior of this function is determined byextension. Theoption andoutput values are typically casted to the corresponding types (for example,ChooseMultipleFilesExtensionOption andChooseMultipleFilesExtensionReturn forChooseMultipleFilesExtension).

You can callsupportsExtension() to check if an extension is supported by the page.

Returns true if the extension was called successfully; otherwise returns false.

See alsosupportsExtension() andExtension.

[signal]void QWebPage::featurePermissionRequestCanceled(QWebFrame * frame,QWebPage::Feature feature)

[signal]void QWebPage::featurePermissionRequested(QWebFrame * frame,QWebPage::Feature feature)

bool QWebPage::findText(constQString & subString,FindFlags options = 0)

Finds the specified string,subString, in the page, using the givenoptions.

If theHighlightAllOccurrences 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 theHighlightAllOccurrences 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 ifsubString was found; otherwise returns false.

bool QWebPage::focusNextPrevChild(bool next)

Similar toQWidget::focusNextPrevChild() it focuses the next focusable web element ifnext is true; otherwise the previous element is focused.

Returns true if it can find a new focusable element, or false if it can't.

QWebFrame * QWebPage::frameAt(constQPoint & pos) const

Returns the frame at the given pointpos, or 0 if there is no frame at that position.

This function was introduced in Qt 4.6.

See alsomainFrame() andcurrentFrame().

[signal]void QWebPage::frameCreated(QWebFrame * frame)

This signal is emitted whenever the page creates a newframe.

See alsocurrentFrame().

[signal]void QWebPage::geometryChangeRequested(constQRect & geom)

This signal is emitted whenever the document wants to change the position and size of the page togeom. This can happen for example through JavaScript.

QWebHistory * QWebPage::history() const

Returns a pointer to the view's history of navigated web pages.

QVariant QWebPage::inputMethodQuery(Qt::InputMethodQuery property) const

This method is used by the input method to query a set of properties of the page to be able to support complex input method operations as support for surrounding text and reconversions.

property specifies which property is queried.

See alsoQWidget::inputMethodEvent(),QInputMethodEvent, andQInputContext.

[virtual protected]void QWebPage::javaScriptAlert(QWebFrame * frame, constQString & msg)

This function is called whenever a JavaScript program running insideframe calls the alert() function with the messagemsg.

The default implementation shows the message,msg, withQMessageBox::information.

[virtual protected]bool QWebPage::javaScriptConfirm(QWebFrame * frame, constQString & msg)

This function is called whenever a JavaScript program running insideframe calls the confirm() function with the message,msg. Returns true if the user confirms the message; otherwise returns false.

The default implementation executes the query usingQMessageBox::information withQMessageBox::Yes andQMessageBox::No buttons.

[virtual protected]void QWebPage::javaScriptConsoleMessage(constQString & message,int lineNumber, constQString & sourceID)

This function is called whenever a JavaScript program tries to print amessage to the web browser's console.

For example in case of evaluation errors the source URL may be provided insourceID as well as thelineNumber.

The default implementation prints nothing.

[virtual protected]bool QWebPage::javaScriptPrompt(QWebFrame * frame, constQString & msg, constQString & defaultValue,QString * result)

This function is called whenever a JavaScript program running insideframe tries to prompt the user for input. The program may provide an optional message,msg, as well as a default value for the input indefaultValue.

If the prompt was cancelled by the user the implementation should return false; otherwise the result should be written toresult and true should be returned. If the prompt was not cancelled by the user, the implementation should return true and the result string must not be null.

The default implementation usesQInputDialog::getText().

[signal]void QWebPage::linkClicked(constQUrl & url)

This signal is emitted whenever the user clicks on a link and the page'slinkDelegationPolicy property is set to delegate the link handling for the specifiedurl.

By default no links are delegated and are handled byQWebPage instead.

Note:This signal possibly won't be emitted for clicked links which use JavaScript to trigger navigation.

See alsolinkHovered().

[signal]void QWebPage::linkHovered(constQString & link, constQString & title, constQString & textContent)

This signal is emitted when the mouse hovers over a link.

link contains the link url.title is the link element's title, if it is specified in the markup.textContent provides text within the link element, e.g., text inside an HTML anchor tag.

When the mouse leaves the link element the signal is emitted with empty parameters.

See alsolinkClicked().

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

This signal is emitted when the page finishes loading content. This signal is independant of script execution or page rendering.ok will indicate whether the load was successful or any error occurred.

See alsoloadStarted() andErrorPageExtension.

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

This signal is emitted when the global progress status changes. The current value is provided byprogress and scales from 0 to 100, which is the default range ofQProgressBar. It accumulates changes from all the child frames.

See alsobytesReceived().

[signal]void QWebPage::loadStarted()

This signal is emitted when a page starts loading content.

See alsoloadFinished().

QWebFrame * QWebPage::mainFrame() const

Returns the main frame of the page.

The main frame provides access to the hierarchy of sub-frames and is also needed if you want to explicitly render a web page into a given painter.

See alsocurrentFrame().

[signal]void QWebPage::menuBarVisibilityChangeRequested(bool visible)

This signal is emitted whenever the visibility of the menubar in a web browser window that hostsQWebPage should be changed tovisible.

[signal]void QWebPage::microFocusChanged()

This signal is emitted when for example the position of the cursor in an editable form element changes. It is used to inform input methods about the new on-screen position where the user is able to enter text. This signal is usually connected to theQWidget::updateMicroFocus() slot.

QNetworkAccessManager * QWebPage::networkAccessManager() const

Returns theQNetworkAccessManager that is responsible for serving network requests for thisQWebPage.

See alsosetNetworkAccessManager().

QWebPluginFactory * QWebPage::pluginFactory() const

Returns theQWebPluginFactory that is responsible for creating plugins embedded into thisQWebPage. If no plugin factory is installed a null pointer is returned.

See alsosetPluginFactory().

[signal]void QWebPage::printRequested(QWebFrame * frame)

This signal is emitted whenever the page requests the web browser to printframe, for example through the JavaScriptwindow.print() call.

See alsoQWebFrame::print() andQPrintPreviewDialog.

[signal]void QWebPage::repaintRequested(constQRect & dirtyRect)

This signal is emitted whenever thisQWebPage should be updated. It's useful when rendering aQWebPage without aQWebView orQGraphicsWebView.dirtyRect contains the area that needs to be updated. To paint theQWebPage get themainFrame() and call the render(QPainter*, constQRegion&) method with thedirtyRect as the second parameter.

See alsomainFrame() andview().

[signal]void QWebPage::restoreFrameStateRequested(QWebFrame * frame)

This signal is emitted when the load offrame is finished and the application may now update its state accordingly.

This function was introduced in Qt 4.5.

[signal]void QWebPage::saveFrameStateRequested(QWebFrame * frame,QWebHistoryItem * item)

This signal is emitted shortly before the history of navigated pages inframe is changed, for example when navigating back in the history.

The providedQWebHistoryItem,item, holds the history entry of the frame before the change.

A potential use-case for this signal is to store custom data in theQWebHistoryItem associated to the frame, usingQWebHistoryItem::setUserData().

This function was introduced in Qt 4.5.

[signal]void QWebPage::scrollRequested(int dx,int dy, constQRect & rectToScroll)

This signal is emitted whenever the content given byrectToScroll needs to be scrolleddx anddy downwards and no view was set.

See alsoview().

[signal]void QWebPage::selectionChanged()

This signal is emitted whenever the selection changes, either interactively or programmatically (e.g. by callingtriggerAction() with a selection action).

See alsoselectedText().

void QWebPage::setActualVisibleContentRect(constQRect & rect) const

void QWebPage::setFeaturePermission(QWebFrame * frame,Feature feature,PermissionPolicy policy)

void QWebPage::setNetworkAccessManager(QNetworkAccessManager * manager)

Sets theQNetworkAccessManagermanager responsible for serving network requests for thisQWebPage.

Note:It is currently not supported to change the network access manager after theQWebPage has used it. The results of doing this are undefined.

See alsonetworkAccessManager().

void QWebPage::setPluginFactory(QWebPluginFactory * factory)

Sets theQWebPluginFactoryfactory responsible for creating plugins embedded into thisQWebPage.

Note: The plugin factory is only used if theQWebSettings::PluginsEnabled attribute is enabled.

See alsopluginFactory().

void QWebPage::setView(QWidget * view)

Sets theview that is associated with the web page.

See alsoview().

QWebSettings * QWebPage::settings() const

Returns a pointer to the page's settings object.

See alsoQWebSettings::globalSettings().

[slot]bool QWebPage::shouldInterruptJavaScript()

This function is called when a JavaScript program is running for a long period of time.

If the user wanted to stop the JavaScript the implementation should return true; otherwise false.

The default implementation executes the query usingQMessageBox::information withQMessageBox::Yes andQMessageBox::No buttons.

Warning: Because of binary compatibility constraints, this function is not virtual. If you want to provide your own implementation in aQWebPage subclass, reimplement the shouldInterruptJavaScript() slot in your subclass instead.QtWebKit will dynamically detect the slot and call it.

This function was introduced in Qt 4.6.

[signal]void QWebPage::statusBarMessage(constQString & text)

This signal is emitted when the statusbartext is changed by the page.

[signal]void QWebPage::statusBarVisibilityChangeRequested(bool visible)

This signal is emitted whenever the visibility of the statusbar in a web browser window that hostsQWebPage should be changed tovisible.

QStringList QWebPage::supportedContentTypes() const

Returns the list of all content types supported byQWebPage.

bool QWebPage::supportsContentType(constQString & mimeType) const

Returns true ifQWebPage can handle the givenmimeType; otherwise, returns false.

[virtual]bool QWebPage::supportsExtension(Extension extension) const

This virtual function returns true if the web page supportsextension; otherwise false is returned.

See alsoextension().

bool QWebPage::swallowContextMenuEvent(QContextMenuEvent * event)

Filters the context menu event,event, through handlers for scrollbars and custom event handlers in the web page. Returns true if the event was handled; otherwise false.

A web page may swallow a context menu event through a custom event handler, allowing for context menus to be implemented in HTML/JavaScript. This is used byGoogle Maps, for example.

[signal]void QWebPage::toolBarVisibilityChangeRequested(bool visible)

This signal is emitted whenever the visibility of the toolbar in a web browser window that hostsQWebPage should be changed tovisible.

quint64 QWebPage::totalBytes() const

Returns the total number of bytes that were received from the network to render the current page, including extra content such as embedded images.

See alsobytesReceived().

[virtual]void QWebPage::triggerAction(WebAction action,bool checked = false)

This function can be called to trigger the specifiedaction. It is also called byQtWebKit if the user triggers the action, for example through a context menu item.

Ifaction is a checkable action thenchecked specified whether the action is toggled or not.

See alsoaction().

QUndoStack * QWebPage::undoStack() const

Returns a pointer to the undo stack used for editable content.

See alsomodified.

[signal]void QWebPage::unsupportedContent(QNetworkReply * reply)

This signal is emitted whenWebKit cannot handle a link the user navigated to or a web server's response includes a "Content-Disposition" header with the 'attachment' directive. If "Content-Disposition" is present inreply, the web server is indicating that the client should prompt the user to save the content regardless of content-type. See RFC 2616 sections 19.5.1 for details about Content-Disposition.

At signal emission time the meta-data of theQNetworkReplyreply is available.

Note:The receiving slot is responsible for deleting theQNetworkReplyreply.

Note:This signal is only emitted if theforwardUnsupportedContent property is set to true.

See alsodownloadRequested().

void QWebPage::updatePositionDependentActions(constQPoint & pos)

Updates the page's actions depending on the positionpos. For example ifpos is over an image element theCopyImageToClipboard action is enabled.

[virtual protected]QString QWebPage::userAgentForUrl(constQUrl & url) const

This function is called when a user agent for HTTP requests is needed. You can reimplement this function to dynamically return different user agents for different URLs, based on theurl parameter.

The default implementation returns the following value:

"Mozilla/5.0 (%Platform%%Security%%Subplatform%) AppleWebKit/%WebKitVersion% (KHTML, like Gecko) %AppVersion Safari/%WebKitVersion%"

On mobile platforms such as Symbian S60 and Maemo, "Mobile Safari" is used instead of "Safari".

In this string the following values are replaced at run-time:

  • %Platform% expands to the windowing system followed by "; " if it is not Windows (e.g. "X11; ").
  • %Security% expands to "N; " if SSL is disabled.
  • %Subplatform% expands to the operating system version (e.g. "Windows NT 6.1" or "Intel Mac OS X 10.5").
  • %WebKitVersion% is the version ofWebKit the application was compiled against.
  • %AppVersion% expands toQCoreApplication::applicationName()/QCoreApplication::applicationVersion() if they're set; otherwise defaulting to Qt and the current Qt version.

QWidget * QWebPage::view() const

Returns the view widget that is associated with the web page.

See alsosetView().

ViewportAttributes QWebPage::viewportAttributesForSize(constQSize & availableSize) const

Computes the optimal viewport configuration given theavailableSize, when user interface components are disregarded.

The configuration is also dependent on the device screen size which is obtained automatically. For testing purposes the size can be overridden by setting two environment variables QTWEBKIT_DEVICE_WIDTH and QTWEBKIT_DEVICE_HEIGHT, which both needs to be set.

TheViewportAttributes includes a pixel density ratio, which will also be exposed to the web author though the -webkit-pixel-ratio media feature. This is the ratio between 1 density-independent pixel (DPI) and physical pixels.

A density-independent pixel is equivalent to one physical pixel on a 160 DPI screen, so on our platform assumes that as the baseline density.

The conversion of DIP units to screen pixels is quite simple:

pixels = DIPs * (density / 160).

Thus, on a 240 DPI screen, 1 DIPs would equal 1.5 physical pixels.

An invalid instance will be returned in the case an empty size is passed to the method.

Note:The density is automatically obtained from the DPI of the screen where the page is being shown, but as many X11 servers are reporting wrong DPI, it is possible to override it usingQX11Info::setAppDpiY().

[signal]void QWebPage::viewportChangeRequested()

Page authors can provide the supplied values by using the viewport meta tag. More information about this can be found atSafari Reference Library: Using the Viewport Meta Tag.

This function was introduced in Qt 4.8.

See alsoQWebPage::ViewportAttributes,setPreferredContentsSize(), andQGraphicsWebView::setScale().

[signal]void QWebPage::windowCloseRequested()

This signal is emitted whenever the page requests the web browser window to be closed, for example through the JavaScriptwindow.close() call.

Related Non-Members

intqWebKitMajorVersion()

Returns the 'major' version number ofWebKit at run-time as an integer (for example, 531). This is the version ofWebKit the application was compiled against.

This function was introduced in Qt 4.6.

See alsoqWebKitVersion().

intqWebKitMinorVersion()

Returns the 'minor' version number ofWebKit at run-time as an integer (for example, 3). This is the version ofWebKit the application was compiled against.

This function was introduced in Qt 4.6.

See alsoqWebKitVersion().

QStringqWebKitVersion()

Returns the version number ofWebKit at run-time as a string (for example, "531.3").

This version is commonly used inWebKit based browsers as part of the user agent string. Web servers and JavaScript might use it to identify the presence of certainWebKit engine features and behaviour.

The evolution of this version is bound to the releases of Apple's Safari browser. For a version specific to theQtWebKit library, seeQTWEBKIT_VERSION

This function was introduced in Qt 4.6.

See alsoQWebPage::userAgentForUrl().

Macro Documentation

QTWEBKIT_VERSION

This macro expands a numeric value of the form 0xMMNNPP (MM = major, NN = minor, PP = patch) that specifiesQtWebKit's version number. For example, if you compile your application againstQtWebKit 2.1.2, the QTWEBKIT_VERSION macro will expand to 0x020102.

You can use QTWEBKIT_VERSION to use the latestQtWebKit API where available.

See alsoQT_VERSION.

QTWEBKIT_VERSION_CHECK

Turns the major, minor and patch numbers of a version into an integer, 0xMMNNPP (MM = major, NN = minor, PP = patch). This can be compared with another similarly processed version id, for example in a preprocessor statement:

#if QTWEBKIT_VERSION >= QTWEBKIT_VERSION_CHECK(2, 1, 0)// code to use API new in QtWebKit 2.1.0#endif

QTWEBKIT_VERSION_STR

This macro expands to a string that specifiesQtWebKit's version number (for example, "2.1.2"). This is the version against which the application is compiled.

See alsoQTWEBKIT_VERSION.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp