QWebFrame Class Reference

#include <mw/QtWebKit/qwebframe.h>

Link against: QtWebKit.lib

class QWebFrame : public QObject, public QObject

The QWebFrame class represents a frame in a web page.

Inherits from

  • QWebFrame
    Public Member Enumerations
    enumRenderLayer { ContentsLayer, ScrollBarLayer, PanIconLayer, AllLayers }
    Public Properties
    QUrl baseUrl
    QSizecontentsSize
    boolfocus
    QIcon icon
    QUrl requestedUrl
    QPointscrollPosition
    qreal textSizeMultiplier
    QString title
    QUrl url
    qreal zoomFactor
    Public Member Functions
    voidaddToJavaScriptWindowObject(const QString &, QObject *)
    voidaddToJavaScriptWindowObject(const QString &, QObject *, QScriptEngine::ValueOwnership)
    QUrl baseUrl()
    QList< QWebFrame * >childFrames()
    QSizecontentsSize()
    QWebElement documentElement()
    virtual boolevent(QEvent *)
    QWebElementCollection findAllElements(const QString &)
    QWebElement findFirstElement(const QString &)
    QString frameName()
    QRectgeometry()
    boolhasFocus()
    QWebHitTestResult hitTestContent(const QPoint &)
    QIcon icon()
    voidload(const QUrl &)
    voidload(const QNetworkRequest &, QNetworkAccessManager::Operation, const QByteArray &)
    QMultiMap< QString, QString >metaData()
    QWebPage *page()
    QWebFrame *parentFrame()
    QPointpos()
    voidrender(QPainter *)
    voidrender(QPainter *, const QRegion &)
    voidrender(QPainter *, RenderLayer, const QRegion &)
    QString renderTreeDump()
    QUrl requestedUrl()
    voidscroll(int, int)
    QRectscrollBarGeometry(Qt::Orientation)
    intscrollBarMaximum(Qt::Orientation)
    intscrollBarMinimum(Qt::Orientation)
    Qt::ScrollBarPolicyscrollBarPolicy(Qt::Orientation)
    intscrollBarValue(Qt::Orientation)
    QPointscrollPosition()
    voidscrollToAnchor(const QString &)
    QWebSecurityOrigin securityOrigin()
    voidsetContent(const QByteArray &, const QString &, const QUrl &)
    voidsetFocus()
    voidsetHtml(const QString &, const QUrl &)
    voidsetScrollBarPolicy(Qt::Orientation, Qt::ScrollBarPolicy)
    voidsetScrollBarValue(Qt::Orientation, int)
    voidsetScrollPosition(const QPoint &)
    voidsetTextSizeMultiplier(qreal)
    voidsetUrl(const QUrl &)
    voidsetZoomFactor(qreal)
    qreal textSizeMultiplier()
    QString title()
    QString toHtml()
    QString toPlainText()
    QUrl url()
    qreal zoomFactor()
    Public Slots
    QVariant evaluateJavaScript(const QString &)
    voidprint(QPrinter *)
    Public Signals
    voidcontentsSizeChanged(const QSize &)
    voidiconChanged()
    voidinitialLayoutCompleted()
    voidjavaScriptWindowObjectCleared()
    voidloadFinished(bool)
    voidloadStarted()
    voidpageChanged()
    voidprovisionalLoad()
    voidtitleChanged(const QString &)
    voidurlChanged(const QUrl &)
    Inherited Attributes
    QObject::d_ptr
    QObject::objectName
    QObject::staticQtMetaObject
    Inherited Functions
    QObject::QObject(QObjectPrivate &,QObject *)
    QObject::blockSignals(bool)
    QObject::childEvent(QChildEvent *)
    QObject::children()const
    QObject::connect(const QObject *,const QMetaMethod &,const QObject *,const QMetaMethod &,Qt::ConnectionType)
    QObject::connect(const QObject *,const char *,const QObject *,const char *,Qt::ConnectionType)
    QObject::connect(const QObject *,const char *,const char *,Qt::ConnectionType)const
    QObject::connectNotify(const char *)
    QObject::customEvent(QEvent *)
    QObject::deleteLater
    QObject::destroyed
    QObject::disconnect(const QObject *,const QMetaMethod &,const QObject *,const QMetaMethod &)
    QObject::disconnect(const QObject *,const char *)
    QObject::disconnect(const QObject *,const char *,const QObject *,const char *)
    QObject::disconnect(const char *,const QObject *,const char *)
    QObject::disconnectNotify(const char *)
    QObject::dumpObjectInfo()
    QObject::dumpObjectTree()
    QObject::dynamicPropertyNames()const
    QObject::eventFilter(QObject *,QEvent *)
    QObject::findChild(const QString &)const
    QObject::findChildren(const QRegExp &)const
    QObject::findChildren(const QString &)const
    QObject::inherits(const char *)const
    QObject::installEventFilter(QObject *)
    QObject::isWidgetType()const
    QObject::killTimer(int)
    QObject::moveToThread(QThread *)
    QObject::objectName()const
    QObject::parent()const
    QObject::property(const char *)const
    QObject::receivers(const char *)const
    QObject::registerUserData()
    QObject::removeEventFilter(QObject *)
    QObject::sender()const
    QObject::senderSignalIndex()const
    QObject::setObjectName(const QString &)
    QObject::setParent(QObject *)
    QObject::setProperty(const char *,const QVariant &)
    QObject::setUserData(uint,QObjectUserData *)
    QObject::signalsBlocked()const
    QObject::startTimer(int)
    QObject::thread()const
    QObject::timerEvent(QTimerEvent *)
    QObject::userData(uint)const
    QObject::~QObject()

    Detailed Description

    Since
    4.4 QtWebKit
    QWebFrame represents a frame inside a web page. Each QWebPage object contains at least one frame, the main frame, obtained using QWebPage::mainFrame(). Additional frames will be created for HTML {<frame>} or {<iframe>} elements.

    A frame can be loaded using load() or setUrl(). Alternatively, if you have the HTML content readily available, you can use setHtml() instead.

    The page() function returns a pointer to the web page object. See {QWebView}{Elements of QWebView} for an explanation of how web frames are related to a web page and web view.

    The QWebFrame class also offers methods to retrieve both the URL currently loaded by the frame (see url()) as well as the URL originally requested to be loaded (see requestedUrl()). These methods make possible the retrieval of the URL before and after a DNS resolution or a redirection occurs during the load process. The requestedUrl() 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 the title() property. Additionally, a frame 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 zoomFactor() 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's {QWebPage::}{frameCreated()} signal to be notified when a new frame is created.

    There are multiple ways to programmatically examine the contents of a frame. The hitTestContent() function can be used to find elements by coordinate. For access to the underlying DOM tree, there is documentElement(), findAllElements() and findFirstElement().

    A QWebFrame 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.

    See also: QWebPage

    Member Enumeration Documentation

    Enum RenderLayer

    This enum describes the layers available for rendering using {QWebFrame::}{render()}. The layers can be OR-ed together from the following list:

    ContentsLayer The web content of the frame ScrollBarLayer The scrollbars of the frame PanIconLayer The icon used when panning the frame

    AllLayers Includes all the above layers

    EnumeratorValueDescription
    ContentsLayer0x10
    ScrollBarLayer0x20
    PanIconLayer0x40
    AllLayers0xff

    Properties Documentation

    baseUrl

    QUrl baseUrl

    the base URL of the frame, can be used to resolve relative URLs

    Since
    4.6

    4.6

    contentsSize

    QSizecontentsSize

    the size of the contents in this frame

    focus

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

    icon

    QIcon icon

    the icon associated with this frame

    requestedUrl

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

    See also: url(), setUrl()

    scrollPosition

    QPointscrollPosition

    the position the frame is currently scrolled to.

    Since
    4.5

    textSizeMultiplier

    qreal textSizeMultiplier

    the scaling factor for all text in the frame

    Use setZoomFactor instead, in combination with the ZoomTextOnly attribute in QWebSettings.

    Note:

    Setting this property also enables the ZoomTextOnly attribute in QWebSettings.

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

    title

    QString title

    the title of the frame as defined by the HTML <title> element

    See also: titleChanged()

    url

    QUrl url

    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.

    See also: urlChanged()

    zoomFactor

    qreal zoomFactor

    the zoom factor for the frame

    Since
    4.5

    Member Function Documentation

    addToJavaScriptWindowObject ( const QString &, QObject * )

    voidaddToJavaScriptWindowObject(const QString &name,
    QObject *object
    )

    Make object available under name from within the frame's JavaScript context. The object 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.

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

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

    The object will never be explicitly deleted by QtWebKit.

    addToJavaScriptWindowObject ( const QString &, QObject *, QScriptEngine::ValueOwnership )

    voidaddToJavaScriptWindowObject(const QString &name,
    QObject *object,
    QScriptEngine::ValueOwnershipownership
    )

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Make object available under name from within the frame's JavaScript context. The object 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.

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

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

    The ownership of object is specified using own.

    baseUrl ( )

    QUrl baseUrl()const

    childFrames ( )

    QList< QWebFrame * >childFrames()const

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

    See also: parentFrame()

    contentsSize ( )

    QSizecontentsSize()const

    contentsSizeChanged ( const QSize & )

    voidcontentsSizeChanged(const QSize &size)[signal]
    Since
    4.6
    This signal is emitted when the frame's contents size changes to size.

    See also: contentsSize()

    documentElement ( )

    QWebElement documentElement()const
    Since
    4.6
    Returns the document element of this frame.

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

    evaluateJavaScript ( const QString & )

    QVariant evaluateJavaScript(const QString &scriptSource)[slot]

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

    See also: addToJavaScriptWindowObject(), javaScriptWindowObjectCleared()

    event ( QEvent * )

    boolevent(QEvent *)[virtual]

    Reimplemented from QObject::event(QEvent *)

    findAllElements ( const QString & )

    QWebElementCollection findAllElements(const QString &selectorQuery)const
    Since
    4.6 Returns a new list of elements matching the given CSS selector selectorQuery. If there are no matching elements, an empty list is returned.
    {http://www.w3.org/TR/REC-CSS2/selector.html#q1}{Standard CSS2 selector} syntax is used for the query.

    See also: QWebElement::findAll()

    findFirstElement ( const QString & )

    QWebElement findFirstElement(const QString &selectorQuery)const
    Since
    4.6 Returns the first element in the frame's document that matches the given CSS selector selectorQuery. If there is no matching element, a null element is returned.
    {http://www.w3.org/TR/REC-CSS2/selector.html#q1}{Standard CSS2 selector} syntax is used for the query.

    See also: QWebElement::findFirst()

    frameName ( )

    QString frameName()const

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

    geometry ( )

    QRectgeometry()const

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

    hasFocus ( )

    boolhasFocus()const

    hitTestContent ( const QPoint & )

    QWebHitTestResult hitTestContent(const QPoint &pos)const

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

    icon ( )

    QIcon icon()const

    iconChanged ( )

    voidiconChanged()[signal]

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

    See also: icon()

    initialLayoutCompleted ( )

    voidinitialLayoutCompleted()[signal]

    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.

    javaScriptWindowObjectCleared ( )

    voidjavaScriptWindowObjectCleared()[signal]

    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 add QObjects to a QWebFrame using addToJavaScriptWindowObject(), you should add them in a slot connected to this signal. This ensures that your objects remain accessible when loading new URLs.

    load ( const QUrl & )

    voidload(const QUrl &url)

    Loads url into this frame.

    Note:

    The view remains the same until enough data has arrived to display the new url.

    See also: setUrl(), setHtml(), setContent()

    load ( const QNetworkRequest &, QNetworkAccessManager::Operation, const QByteArray & )

    voidload(const QNetworkRequest &request,
    QNetworkAccessManager::Operationoperation = QNetworkAccessManager::GetOperation,
    const QByteArray &body = QByteArray()
    )

    Loads a network request, req, into this frame, using the method specified in 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 content.

    See also: setUrl()

    loadFinished ( bool )

    voidloadFinished(boolok)[signal]
    Since
    4.6
    This signal is emitted when a load of this frame is finished. ok will indicate whether the load was successful or any error occurred.

    See also: loadStarted()

    loadStarted ( )

    voidloadStarted()[signal]
    Since
    4.6
    This signal is emitted when a new load of this frame is started.

    See also: loadFinished()

    metaData ( )

    QMultiMap< QString, QString >metaData()const

    Returns the meta data in this frame as a QMultiMap.

    Since
    4.5 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: Key Value "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.

    page ( )

    QWebPage *page()const

    The web page that contains this frame.

    See also: pageChanged()

    pageChanged ( )

    voidpageChanged()[signal]
    Since
    4.7
    This signal is emitted when this frame has been moved to a different QWebPage.

    See also: page()

    parentFrame ( )

    QWebFrame *parentFrame()const

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

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

    See also: childFrames()

    pos ( )

    QPointpos()const

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

    print ( QPrinter * )

    voidprint(QPrinter *printer)const [slot]

    Prints the frame to the given printer.

    See also: render()

    provisionalLoad ( )

    voidprovisionalLoad()[signal]

    render ( QPainter * )

    voidrender(QPainter *)

    Render the frame into painter.

    render ( QPainter *, const QRegion & )

    voidrender(QPainter *,
    const QRegion &clip
    )

    Render the frame into painter clipping to clip.

    render ( QPainter *, RenderLayer, const QRegion & )

    voidrender(QPainter *,
    RenderLayerlayer,
    const QRegion &clip = QRegion()
    )
    Since
    4.6 Render the layer of the frame using painter clipping to clip.

    See also: print()

    renderTreeDump ( )

    QString renderTreeDump()const

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

    requestedUrl ( )

    QUrl requestedUrl()const

    scroll ( int, int )

    voidscroll(int,
    int
    )
    Since
    4.5 Scrolls the frame dx pixels to the right and dy pixels downward. Both dx and dy may be negative.

    See also: QWebFrame::scrollPosition

    scrollBarGeometry ( Qt::Orientation )

    QRectscrollBarGeometry(Qt::Orientationorientation)const
    Since
    4.6 Returns the geometry for the scrollbar with orientation orientation.
    If the scrollbar does not exist an empty rect is returned.

    scrollBarMaximum ( Qt::Orientation )

    intscrollBarMaximum(Qt::Orientationorientation)const

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

    See also: scrollBarMinimum()

    scrollBarMinimum ( Qt::Orientation )

    intscrollBarMinimum(Qt::Orientationorientation)const

    Returns the minimum value for the scrollbar with orientation orientation.

    The minimum value is always 0.

    See also: scrollBarMaximum()

    scrollBarPolicy ( Qt::Orientation )

    Qt::ScrollBarPolicyscrollBarPolicy(Qt::Orientationorientation)const

    Returns the scrollbar policy for the scrollbar defined by orientation.

    scrollBarValue ( Qt::Orientation )

    intscrollBarValue(Qt::Orientationorientation)const

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

    See also: scrollBarMinimum(), scrollBarMaximum()

    scrollPosition ( )

    QPointscrollPosition()const

    scrollToAnchor ( const QString & )

    voidscrollToAnchor(const QString &anchor)
    Since
    4.7 Scrolls the frame to the given anchor name.

    securityOrigin ( )

    QWebSecurityOrigin securityOrigin()const
    Since
    4.5
    Returns the frame's security origin.

    setContent ( const QByteArray &, const QString &, const QUrl & )

    voidsetContent(const QByteArray &data,
    const QString &mimeType = QString(),
    const QUrl &baseUrl = QUrl()
    )

    Sets the content of this frame 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.

    Note:

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

    See also: toHtml(), setHtml()

    setFocus ( )

    voidsetFocus()
    Since
    4.6
    Gives keyboard input focus to this frame.

    setHtml ( const QString &, const QUrl & )

    voidsetHtml(const QString &html,
    const QUrl &baseUrl = QUrl()
    )

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

    The html is loaded immediately; external objects are loaded asynchronously.

    If a script in the html 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 subsequent html will be 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. It is also possible for the encoding to be specified by web server.

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

    Note:

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

    CAUTION:

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

    See also: toHtml(), setContent(), load()

    setScrollBarPolicy ( Qt::Orientation, Qt::ScrollBarPolicy )

    voidsetScrollBarPolicy(Qt::Orientationorientation,
    Qt::ScrollBarPolicypolicy
    )

    Sets the scrollbar policy for the scrollbar defined by orientation to policy.

    setScrollBarValue ( Qt::Orientation, int )

    voidsetScrollBarValue(Qt::Orientationorientation,
    intvalue
    )

    Sets the current value for the scrollbar with orientation orientation.

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

    Changing the value also updates the thumb position.

    See also: scrollBarMinimum(), scrollBarMaximum()

    setScrollPosition ( const QPoint & )

    voidsetScrollPosition(const QPoint &pos)

    setTextSizeMultiplier ( qreal )

    voidsetTextSizeMultiplier(qrealfactor)

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

    setUrl ( const QUrl & )

    voidsetUrl(const QUrl &url)

    setZoomFactor ( qreal )

    voidsetZoomFactor(qrealfactor)

    textSizeMultiplier ( )

    qreal textSizeMultiplier()const

    title ( )

    QString title()const

    titleChanged ( const QString & )

    voidtitleChanged(const QString &title)[signal]

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

    See also: title()

    toHtml ( )

    QString toHtml()const

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

    See also: setHtml(), toPlainText()

    toPlainText ( )

    QString toPlainText()const

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

    See also: toHtml()

    url ( )

    QUrl url()const

    urlChanged ( const QUrl & )

    voidurlChanged(const QUrl &url)[signal]

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

    See also: url()

    zoomFactor ( )

    qreal zoomFactor()const