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

QWebFrame Class

TheQWebFrame class represents a frame in a web page.More...

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

Public Types

enumRenderLayer { ContentsLayer, ScrollBarLayer, PanIconLayer, AllLayers }

Properties

Public Functions

voidaddToJavaScriptWindowObject(const QString & name, QObject * object)
voidaddToJavaScriptWindowObject(const QString & name, QObject * object, QScriptEngine::ValueOwnership own)
QUrlbaseUrl() const
QList<QWebFrame *>childFrames() const
QSizecontentsSize() const
QWebElementdocumentElement() const
QWebElementCollectionfindAllElements(const QString & selectorQuery) const
QWebElementfindFirstElement(const QString & selectorQuery) const
QStringframeName() const
QRectgeometry() const
boolhasFocus() const
QWebHitTestResulthitTestContent(const QPoint & pos) const
QIconicon() const
voidload(const QUrl & url)
voidload(const QNetworkRequest & req, QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, const QByteArray & body = QByteArray())
QMultiMap<QString, QString>metaData() const
QWebPage *page() const
QWebFrame *parentFrame() const
QPointpos() const
voidrender(QPainter * painter)
voidrender(QPainter * painter, const QRegion & clip)
voidrender(QPainter * painter, RenderLayer layer, const QRegion & clip = QRegion())
QStringrenderTreeDump() const
QUrlrequestedUrl() const
voidscroll(int dx, int dy)
QRectscrollBarGeometry(Qt::Orientation orientation) const
intscrollBarMaximum(Qt::Orientation orientation) const
intscrollBarMinimum(Qt::Orientation orientation) const
Qt::ScrollBarPolicyscrollBarPolicy(Qt::Orientation orientation) const
intscrollBarValue(Qt::Orientation orientation) const
QPointscrollPosition() const
voidscrollToAnchor(const QString & anchor)
QWebSecurityOriginsecurityOrigin() const
voidsetContent(const QByteArray & data, const QString & mimeType = QString(), const QUrl & baseUrl = QUrl())
voidsetFocus()
voidsetHtml(const QString & html, const QUrl & baseUrl = QUrl())
voidsetScrollBarPolicy(Qt::Orientation orientation, Qt::ScrollBarPolicy policy)
voidsetScrollBarValue(Qt::Orientation orientation, int value)
voidsetScrollPosition(const QPoint & pos)
voidsetTextSizeMultiplier(qreal factor)
voidsetUrl(const QUrl & url)
voidsetZoomFactor(qreal factor)
qrealtextSizeMultiplier() const
QStringtitle() const
QStringtoHtml() const
QStringtoPlainText() const
QUrlurl() const
qrealzoomFactor() const

Reimplemented Public Functions

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

Public Slots

QVariantevaluateJavaScript(const QString & scriptSource)
voidprint(QPrinter * printer) const
  • 1 public slot inherited fromQObject

Signals

voidcontentsSizeChanged(const QSize & size)
voidiconChanged()
voidinitialLayoutCompleted()
voidjavaScriptWindowObjectCleared()
voidloadFinished(bool ok)
voidloadStarted()
voidpageChanged()
voidtitleChanged(const QString & title)
voidurlChanged(const QUrl & url)

Additional Inherited Members

  • 7 static public members inherited fromQObject
  • 8 protected functions inherited fromQObject

Detailed Description

TheQWebFrame class represents a frame in a web page.

QWebFrame represents a frame inside a web page. EachQWebPage object contains at least one frame, the main frame, obtained usingQWebPage::mainFrame(). Additional frames will be created for HTML<frame> or<iframe> elements.

A frame can be loaded usingload() orsetUrl(). Alternatively, if you have the HTML content readily available, you can usesetHtml() instead.

Thepage() function returns a pointer to the web page object. SeeElements of QWebView for an explanation of how web frames are related to a web page and web view.

TheQWebFrame class also offers methods to retrieve both the URL currently loaded by the frame (seeurl()) as well as the URL originally requested to be loaded (seerequestedUrl()). These methods make possible the retrieval of the URL before and after a DNS resolution or a redirection occurs during the load process. TherequestedUrl() also matches to the URL added to the frame history (QWebHistory) if load is successful.

The title of an HTML frame can be accessed with thetitle() property. Additionally, a frame may also specify an icon, which can be accessed using theicon() property. If the title or the icon changes, the correspondingtitleChanged() andiconChanged() signals will be emitted. ThezoomFactor() property can be used to change the overall size of the content displayed in the frame.

QWebFrame objects are created and controlled by the web page. You can connect to the web page'sframeCreated() signal to be notified when a new frame is created.

There are multiple ways to programmatically examine the contents of a frame. ThehitTestContent() function can be used to find elements by coordinate. For access to the underlying DOM tree, there isdocumentElement(),findAllElements() andfindFirstElement().

AQWebFrame can be printed onto aQPrinter using theprint() function. This function is marked as a slot and can be conveniently connected toQPrintPreviewDialog'spaintRequested() signal.

See alsoQWebPage.

Member Type Documentation

enum QWebFrame::RenderLayer

This enum describes the layers available for rendering usingrender(). The layers can be OR-ed together from the following list:

ConstantValueDescription
QWebFrame::ContentsLayer0x10The web content of the frame
QWebFrame::ScrollBarLayer0x20The scrollbars of the frame
QWebFrame::PanIconLayer0x40The icon used when panning the frame
QWebFrame::AllLayers0xffIncludes all the above layers

Property Documentation

baseUrl : constQUrl

This property holds the base URL of the frame, can be used to resolve relative URLs.

This property was introduced in Qt 4.6.

Access functions:

QUrlbaseUrl() const

contentsSize : constQSize

This property holds the size of the contents in this frame.

Access functions:

QSizecontentsSize() const

See alsocontentsSizeChanged().

focus : constbool

Returns true if this frame has keyboard input focus; otherwise, returns false.

This property was introduced in Qt 4.6.

Access functions:

boolhasFocus() const

icon : constQIcon

This property holds the icon associated with this frame.

Access functions:

QIconicon() const

See alsoiconChanged() andQWebSettings::iconForUrl().

requestedUrl : constQUrl

The URL requested to loaded by the frame currently viewed. The URL may differ from the one returned byurl() if a DNS resolution or a redirection occurs.

This property was introduced in Qt 4.6.

Access functions:

QUrlrequestedUrl() const

See alsourl() andsetUrl().

scrollPosition :QPoint

This property holds the position the frame is currently scrolled to.

This property was introduced in Qt 4.5.

Access functions:

QPointscrollPosition() const
voidsetScrollPosition(const QPoint & pos)

title : constQString

This property holds the title of the frame as defined by the HTML <title> element.

Access functions:

QStringtitle() const

See alsotitleChanged().

url :QUrl

This property holds the url of the frame currently viewed.

Setting this property clears the view and loads the URL.

By default, this property contains an empty, invalid URL.

Access functions:

QUrlurl() const
voidsetUrl(const QUrl & url)

See alsourlChanged().

zoomFactor :qreal

This property holds the zoom factor for the frame.

This property was introduced in Qt 4.5.

Access functions:

qrealzoomFactor() const
voidsetZoomFactor(qreal factor)

Member Function Documentation

void QWebFrame::addToJavaScriptWindowObject(constQString & name,QObject * object)

Makeobject available undername from within the frame's JavaScript context. Theobject will be inserted as a child of the frame's window object.

Qt properties will be exposed as JavaScript properties and slots as JavaScript methods. The interaction between C++ and JavaScript is explained in the documentation of theQtWebKit bridge.

If you want to ensure that yourQObjects remain accessible after loading a new URL, you should add them in a slot connected to thejavaScriptWindowObjectCleared() signal.

If Javascript is not enabled for this page, then this method does nothing.

Theobject will never be explicitly deleted byQtWebKit.

void QWebFrame::addToJavaScriptWindowObject(constQString & name,QObject * object,QScriptEngine::ValueOwnership own)

This is an overloaded function.

Makeobject available undername from within the frame's JavaScript context. Theobject will be inserted as a child of the frame's window object.

Qt properties will be exposed as JavaScript properties and slots as JavaScript methods. The interaction between C++ and JavaScript is explained in the documentation of theQtWebKit bridge.

If you want to ensure that yourQObjects remain accessible after loading a new URL, you should add them in a slot connected to thejavaScriptWindowObjectCleared() signal.

If Javascript is not enabled for this page, then this method does nothing.

The ownership ofobject is specified usingown.

QList<QWebFrame *> QWebFrame::childFrames() const

Returns a list of all frames that are direct children of this frame.

See alsoparentFrame().

[signal]void QWebFrame::contentsSizeChanged(constQSize & size)

This signal is emitted when the frame's contents size changes tosize.

This function was introduced in Qt 4.6.

See alsocontentsSize().

QWebElement QWebFrame::documentElement() const

Returns the document element of this frame.

The document element provides access to the entire structured content of the frame.

This function was introduced in Qt 4.6.

[slot]QVariant QWebFrame::evaluateJavaScript(constQString & scriptSource)

Evaluates the JavaScript defined byscriptSource using this frame as context and returns the result of the last executed statement.

See alsoaddToJavaScriptWindowObject() andjavaScriptWindowObjectCleared().

[virtual]bool QWebFrame::event(QEvent * e)

Reimplemented fromQObject::event().

QWebElementCollection QWebFrame::findAllElements(constQString & selectorQuery) const

Returns a new list of elements matching the given CSS selectorselectorQuery. If there are no matching elements, an empty list is returned.

Standard CSS2 selector syntax is used for the query.

This function was introduced in Qt 4.6.

See alsoQWebElement::findAll().

QWebElement QWebFrame::findFirstElement(constQString & selectorQuery) const

Returns the first element in the frame's document that matches the given CSS selectorselectorQuery. If there is no matching element, a null element is returned.

Standard CSS2 selector syntax is used for the query.

This function was introduced in Qt 4.6.

See alsoQWebElement::findFirst().

QString QWebFrame::frameName() const

The name of this frame as defined by the parent frame.

QRect QWebFrame::geometry() const

Return the geometry of the frame relative to it's parent frame.

QWebHitTestResult QWebFrame::hitTestContent(constQPoint & pos) const

Performs a hit test on the frame contents at the given positionpos and returns the hit test result.

[signal]void QWebFrame::iconChanged()

This signal is emitted when the icon ("favicon") associated with the frame has been loaded.

See alsoicon().

[signal]void QWebFrame::initialLayoutCompleted()

This signal is emitted when the frame is laid out the first time. This is the first time you will see contents displayed on the frame.

Note:A frame can be laid out multiple times.

[signal]void QWebFrame::javaScriptWindowObjectCleared()

This signal is emitted whenever the global window object of the JavaScript environment is cleared, e.g., before starting a new load.

If you intend to addQObjects to aQWebFrame usingaddToJavaScriptWindowObject(), you should add them in a slot connected to this signal. This ensures that your objects remain accessible when loading new URLs.

void QWebFrame::load(constQUrl & url)

Loadsurl into this frame.

Note:The view remains the same until enough data has arrived to display the newurl.

See alsosetUrl(),setHtml(), andsetContent().

void QWebFrame::load(constQNetworkRequest & req,QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, constQByteArray & body = QByteArray())

Loads a network request,req, into this frame, using the method specified inoperation.

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 content.

See alsosetUrl().

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

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

This function was introduced in Qt 4.6.

See alsoloadStarted().

[signal]void QWebFrame::loadStarted()

This signal is emitted when a new load of this frame is started.

This function was introduced in Qt 4.6.

See alsoloadFinished().

QMultiMap<QString,QString> QWebFrame::metaData() const

Returns the meta data in this frame as aQMultiMap

The meta data consists of the name and content attributes of the of the<meta> tags in the HTML document.

For example:

<html><head><meta name="description" content="This document is a tutorial about Qt development"><meta name="keywords" content="Qt, WebKit, Programming"></head>...</html>

Given the above HTML code the metaData() function will return a map with two entries:

KeyValue
"description""This document is a tutorial about Qt development"
"keywords""Qt,WebKit, Programming"

This function returns a multi map to support multiple meta tags with the same attribute name.

This function was introduced in Qt 4.5.

QWebPage * QWebFrame::page() const

The web page that contains this frame.

See alsopageChanged().

[signal]void QWebFrame::pageChanged()

This signal is emitted when this frame has been moved to a differentQWebPage.

This function was introduced in Qt 4.7.

See alsopage().

QWebFrame * QWebFrame::parentFrame() const

Returns the parent frame of this frame, or 0 if the frame is the web pages main frame.

This is equivalent toqobject_cast<QWebFrame*>(frame->parent()).

See alsochildFrames().

QPoint QWebFrame::pos() const

Returns the position of the frame relative to it's parent frame.

[slot]void QWebFrame::print(QPrinter * printer) const

Prints the frame to the givenprinter.

See alsorender().

void QWebFrame::render(QPainter * painter)

Render the frame intopainter.

void QWebFrame::render(QPainter * painter, constQRegion & clip)

Render the frame intopainter clipping toclip.

void QWebFrame::render(QPainter * painter,RenderLayer layer, constQRegion & clip = QRegion())

Render thelayer of the frame usingpainter clipping toclip.

This function was introduced in Qt 4.6.

See alsoprint().

QString QWebFrame::renderTreeDump() const

Returns a dump of the rendering tree. This is mainly useful for debugging html.

void QWebFrame::scroll(int dx,int dy)

Scrolls the framedx pixels to the right anddy pixels downward. Bothdx anddy may be negative.

This function was introduced in Qt 4.5.

See alsoQWebFrame::scrollPosition.

QRect QWebFrame::scrollBarGeometry(Qt::Orientation orientation) const

Returns the geometry for the scrollbar with orientationorientation.

If the scrollbar does not exist an empty rect is returned.

This function was introduced in Qt 4.6.

int QWebFrame::scrollBarMaximum(Qt::Orientation orientation) const

Returns the maximum value for the scrollbar with orientationorientation, or 0 if no scrollbar is found fororientation.

See alsoscrollBarMinimum().

int QWebFrame::scrollBarMinimum(Qt::Orientation orientation) const

Returns the minimum value for the scrollbar with orientationorientation.

The minimum value is always 0.

See alsoscrollBarMaximum().

Qt::ScrollBarPolicy QWebFrame::scrollBarPolicy(Qt::Orientation orientation) const

Returns the scrollbar policy for the scrollbar defined byorientation.

See alsosetScrollBarPolicy().

int QWebFrame::scrollBarValue(Qt::Orientation orientation) const

Returns the current value for the scrollbar with orientationorientation, or 0 if no scrollbar is found fororientation.

See alsosetScrollBarValue(),scrollBarMinimum(), andscrollBarMaximum().

void QWebFrame::scrollToAnchor(constQString & anchor)

Scrolls the frame to the givenanchor name.

This function was introduced in Qt 4.7.

QWebSecurityOrigin QWebFrame::securityOrigin() const

Returns the frame's security origin.

This function was introduced in Qt 4.5.

void QWebFrame::setContent(constQByteArray & data, constQString & mimeType = QString(), constQUrl & baseUrl = QUrl())

Sets the content of this frame to the specified contentdata. If themimeType 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 tobaseUrl.

Thedata is loaded immediately; external objects are loaded asynchronously.

Note:This method will not affect session or global history for the frame.

See alsotoHtml() andsetHtml().

void QWebFrame::setFocus()

Gives keyboard input focus to this frame.

This function was introduced in Qt 4.6.

See alsohasFocus().

void QWebFrame::setHtml(constQString & html, constQUrl & baseUrl = QUrl())

Sets the content of this frame tohtml.baseUrl is optional and used to resolve relative URLs in the document, such as referenced images or stylesheets.

Thehtml is loaded immediately; external objects are loaded asynchronously.

If a script in thehtml runs longer than the default script timeout (currently 10 seconds), for example due to being blocked by a modal JavaScript alert dialog, this method will return as soon as possible after the timeout and any subsequenthtml will be loaded asynchronously.

When using this methodWebKit 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. It is also possible for the encoding to be specified by web server.

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

Note:This method will not affect session or global history for the frame.

Warning: This function works only for HTML, for other mime types (i.e. XHTML, SVG)setContent() should be used instead.

See alsotoHtml(),setContent(), andload().

void QWebFrame::setScrollBarPolicy(Qt::Orientation orientation,Qt::ScrollBarPolicy policy)

Sets the scrollbar policy for the scrollbar defined byorientation topolicy.

See alsoscrollBarPolicy().

void QWebFrame::setScrollBarValue(Qt::Orientation orientation,int value)

Sets the currentvalue for the scrollbar with orientationorientation.

The scrollbar forces thevalue to be within the legal range: minimum <= value <= maximum.

Changing the value also updates the thumb position.

See alsoscrollBarValue(),scrollBarMinimum(), andscrollBarMaximum().

void QWebFrame::setTextSizeMultiplier(qreal factor)

Sets the value of the multiplier used to scale the text in a Web frame to thefactor specified.

See alsotextSizeMultiplier().

qreal QWebFrame::textSizeMultiplier() const

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

See alsosetTextSizeMultiplier().

[signal]void QWebFrame::titleChanged(constQString & title)

This signal is emitted whenever the title of the frame changes. Thetitle string specifies the new title.

See alsotitle().

QString QWebFrame::toHtml() const

Returns the frame's content as HTML, enclosed in HTML and BODY tags.

See alsosetHtml() andtoPlainText().

QString QWebFrame::toPlainText() const

Returns the content of this frame converted to plain text, completely stripped of all HTML formatting.

See alsotoHtml().

[signal]void QWebFrame::urlChanged(constQUrl & url)

This signal is emitted with the URL of the frame when the frame's title is received. The new URL is specified byurl.

See alsourl().

© 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