QGraphicsWebView Class

The QGraphicsWebView class allows Web content to be added to a GraphicsView. More...

Header: #include <QGraphicsWebView>
qmake: QT += webkitwidgets
Since: Qt 4.6

This class was introduced in Qt 4.6.

Properties

Public Functions

QGraphicsWebView(QGraphicsItem *parent = Q_NULLPTR)
virtual ~QGraphicsWebView()
bool findText(const QString &subString, QWebPage::FindFlags options = QWebPage::FindFlags())
QWebHistory *history() const
QIcon icon() const
bool isModified() const
bool isTiledBackingStoreFrozen() const
void load(const QUrl &url)
QWebPage *page() const
QAction *pageAction(QWebPage::WebAction action) const
QPainter::RenderHints renderHints() const
bool resizesToContents() const
void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl())
void setHtml(const QString &html, const QUrl &baseUrl = QUrl())
void setPage(QWebPage *page)
void setRenderHint(QPainter::RenderHint hint, bool enabled = true)
void setRenderHints(QPainter::RenderHints hints)
void setResizesToContents(bool enabled)
void setTiledBackingStoreFrozen(bool frozen)
void setUrl(const QUrl &)
void setZoomFactor(qreal)
QWebSettings *settings() const
QString title() const
void triggerPageAction(QWebPage::WebAction action, bool checked = false)
QUrl url() const
qreal zoomFactor() const

Reimplemented Public Functions

virtual bool event(QEvent *event) override
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const override
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR) override
virtual void setGeometry(const QRectF &rect) override
virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const override
virtual void updateGeometry() override

Public Slots

void back()
void forward()
void reload()
void stop()

Signals

void iconChanged()
void titleChanged(const QString &)
void urlChanged(const QUrl &)

Reimplemented Protected Functions

virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *ev) override
virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *ev) override
virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *ev) override
virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *ev) override
virtual void dropEvent(QGraphicsSceneDragDropEvent *ev) override
virtual void focusInEvent(QFocusEvent *ev) override
virtual bool focusNextPrevChild(bool next) override
virtual void focusOutEvent(QFocusEvent *ev) override
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *ev) override
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *ev) override
virtual void inputMethodEvent(QInputMethodEvent *ev) override
virtual void keyPressEvent(QKeyEvent *ev) override
virtual void keyReleaseEvent(QKeyEvent *ev) override
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *ev) override
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *ev) override
virtual void mousePressEvent(QGraphicsSceneMouseEvent *ev) override
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *ev) override
virtual bool sceneEvent(QEvent *event) override
virtual void wheelEvent(QGraphicsSceneWheelEvent *ev) override

Detailed Description

An instance of this class renders Web content from a URL or supplied as data, using features of the Qt WebKit module.

If the width and height of the item are not set, they will default to 800 and 600, respectively. If the Web page contents is larger than that, scrollbars will be shown if not disabled explicitly.

Browser Features

Many of the functions, signals and properties provided by QWebView are also available for this item, making it simple to adapt existing code to use QGraphicsWebView instead of QWebView.

The item uses a QWebPage object to perform the rendering of Web content, and this can be obtained with the page() function, enabling the document itself to be accessed and modified.

As with QWebView, the item records the browsing history using a QWebHistory object, accessible using the history() function. The QWebSettings object that defines the configuration of the browser can be obtained with the settings() function, enabling features like plugin support to be customized for each item.

See also QWebView and QGraphicsTextItem.

Property Documentation

icon : const QIcon

This property holds the icon associated with the web page currently viewed

By default, this property contains a null icon.

In order for icons to be loaded, you will need to set an icon database path using QWebSettings::setIconDatabasePath().

Access functions:

QIcon icon() const

Notifier signal:

void iconChanged()

See also QWebSettings::iconForUrl() and QWebSettings::setIconDatabasePath().

modified : const bool

This property holds whether the document was modified by the user

Parts of HTML documents can be editable for example through the contenteditable attribute on HTML elements.

By default, this property is false.

Access functions:

bool isModified() const

renderHints : QPainter::RenderHints

This property holds the default render hints for the view

These hints are used to initialize QPainter before painting the Web page.

QPainter::TextAntialiasing and QPainter::SmoothPixmapTransform are enabled by default and will be used to render the item in addition of what has been set on the painter given by QGraphicsScene.

This property was introduced in Qt 4.8.

Access functions:

QPainter::RenderHints renderHints() const
void setRenderHints(QPainter::RenderHints hints)

See also QPainter::renderHints().

resizesToContents : bool

This property holds whether the size of the QGraphicsWebView and its viewport changes to match the contents size

If this property is set, the QGraphicsWebView will automatically change its size to match the size of the main frame contents. As a result the top level frame will never have scrollbars. It will also make CSS fixed positioning to behave like absolute positioning with elements positioned relative to the document instead of the viewport.

This property should be used in conjunction with the QWebPage::preferredContentsSize property. If not explicitly set, the preferredContentsSize is automatically set to a reasonable value.

This property was introduced in Qt 4.7.

Access functions:

bool resizesToContents() const
void setResizesToContents(bool enabled)

See also QWebPage::setPreferredContentsSize().

tiledBackingStoreFrozen : bool

This property holds whether the tiled backing store updates its contents

If the tiled backing store is enabled using QWebSettings::TiledBackingStoreEnabled attribute, this property can be used to disable backing store updates temporarily. This can be useful for example for running a smooth animation that changes the scale of the QGraphicsWebView.

When the backing store is unfrozen, its contents will be automatically updated to match the current state of the document. If the QGraphicsWebView scale was changed, the backing store is also re-rendered using the new scale.

If the tiled backing store is not enabled, this property does nothing.

This property was introduced in Qt 4.7.

Access functions:

bool isTiledBackingStoreFrozen() const
void setTiledBackingStoreFrozen(bool frozen)

See also QWebSettings::TiledBackingStoreEnabled and QGraphicsObject::scale.

title : const QString

This property holds the title of the web page currently viewed

By default, this property contains an empty string.

Access functions:

QString title() const

Notifier signal:

void titleChanged(const QString &)

url : QUrl

This property holds the url of the web page currently viewed

Setting this property clears the view and loads the URL.

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

Access functions:

QUrl url() const
void setUrl(const QUrl &)

Notifier signal:

void urlChanged(const QUrl &)

See also load().

zoomFactor : qreal

This property holds the zoom factor for the view

Access functions:

qreal zoomFactor() const
void setZoomFactor(qreal)

Member Function Documentation

QGraphicsWebView::QGraphicsWebView(QGraphicsItem *parent = Q_NULLPTR)

Constructs an empty QGraphicsWebView with parent parent.

See also load().

[slot] void QGraphicsWebView::back()

Convenience slot that loads the previous document in the list of documents built by navigating links. Does nothing if there is no previous document.

See also forward().

[slot] void QGraphicsWebView::forward()

Convenience slot that loads the next document in the list of documents built by navigating links. Does nothing if there is no next document.

See also back().

[slot] void QGraphicsWebView::reload()

Reloads the current document.

See also stop() and loadStarted().

[slot] void QGraphicsWebView::stop()

Convenience slot that stops loading the document.

See also reload() and loadFinished().

[virtual] QGraphicsWebView::~QGraphicsWebView()

Destroys the item.

[override virtual protected] void QGraphicsWebView::contextMenuEvent(QGraphicsSceneContextMenuEvent *ev)

[override virtual protected] void QGraphicsWebView::dragEnterEvent(QGraphicsSceneDragDropEvent *ev)

[override virtual protected] void QGraphicsWebView::dragLeaveEvent(QGraphicsSceneDragDropEvent *ev)

[override virtual protected] void QGraphicsWebView::dragMoveEvent(QGraphicsSceneDragDropEvent *ev)

[override virtual protected] void QGraphicsWebView::dropEvent(QGraphicsSceneDragDropEvent *ev)

[override virtual] bool QGraphicsWebView::event(QEvent *event)

bool QGraphicsWebView::findText(const QString &subString, QWebPage::FindFlags options = QWebPage::FindFlags())

Finds the specified string, subString, in the page, using the given options.

If the HighlightAllOccurrences flag is passed, the function will highlight all occurrences that exist in the page. All subsequent calls will extend the highlight, rather than replace it, with occurrences of the new string.

If the HighlightAllOccurrences flag is not passed, the function will select an occurrence and all subsequent calls will replace the current occurrence with the next one.

To clear the selection, just pass an empty string.

Returns true if subString was found; otherwise returns false.

See also QWebPage::selectedText() and QWebPage::selectionChanged().

[override virtual protected] void QGraphicsWebView::focusInEvent(QFocusEvent *ev)

[override virtual protected] bool QGraphicsWebView::focusNextPrevChild(bool next)

[override virtual protected] void QGraphicsWebView::focusOutEvent(QFocusEvent *ev)

QWebHistory *QGraphicsWebView::history() const

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

It is equivalent to

     view->page()->history();

[override virtual protected] void QGraphicsWebView::hoverLeaveEvent(QGraphicsSceneHoverEvent *ev)

[override virtual protected] void QGraphicsWebView::hoverMoveEvent(QGraphicsSceneHoverEvent *ev)

[override virtual protected] void QGraphicsWebView::inputMethodEvent(QInputMethodEvent *ev)

[override virtual] QVariant QGraphicsWebView::inputMethodQuery(Qt::InputMethodQuery query) const

[override virtual] QVariant QGraphicsWebView::itemChange(GraphicsItemChange change, const QVariant &value)

[override virtual protected] void QGraphicsWebView::keyPressEvent(QKeyEvent *ev)

[override virtual protected] void QGraphicsWebView::keyReleaseEvent(QKeyEvent *ev)

void QGraphicsWebView::load(const QUrl &url)

Loads the specified url and displays it.

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

See also setUrl() and url().

[override virtual protected] void QGraphicsWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *ev)

[override virtual protected] void QGraphicsWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *ev)

[override virtual protected] void QGraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent *ev)

[override virtual protected] void QGraphicsWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *ev)

QWebPage *QGraphicsWebView::page() const

Returns a pointer to the underlying web page.

See also setPage().

QAction *QGraphicsWebView::pageAction(QWebPage::WebAction action) const

Returns a pointer to a QAction that encapsulates the specified web action action.

[override virtual] void QGraphicsWebView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR)

QPainter::RenderHints QGraphicsWebView::renderHints() const

Returns the render hints used by the view to render content.

Note: Getter function for property renderHints.

This function was introduced in Qt 4.8.

See also setRenderHints() and QPainter::renderHints().

[override virtual protected] bool QGraphicsWebView::sceneEvent(QEvent *event)

void QGraphicsWebView::setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl())

Sets the content of the web graphicsitem 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.

See also load(), setHtml(), and QWebFrame::toHtml().

[override virtual] void QGraphicsWebView::setGeometry(const QRectF &rect)

void QGraphicsWebView::setHtml(const QString &html, const QUrl &baseUrl = QUrl())

Sets the content of the web view to the specified html.

External objects such as stylesheets or images referenced in the HTML document are located relative to baseUrl.

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

When using this method, WebKit assumes that external resources such as JavaScript programs or style sheets are encoded in UTF-8 unless otherwise specified. For example, the encoding of an external script can be specified through the charset attribute of the HTML script tag. Alternatively, the encoding can also be specified by the web server.

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

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

See also load(), setContent(), QWebFrame::toHtml(), and QWebFrame::setContent().

void QGraphicsWebView::setPage(QWebPage *page)

Makes page the new web page of the web graphicsitem.

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.

See also page().

void QGraphicsWebView::setRenderHint(QPainter::RenderHint hint, bool enabled = true)

If enabled is true, enables the specified render hint; otherwise disables it.

This function was introduced in Qt 4.8.

See also renderHints and QPainter::renderHints().

void QGraphicsWebView::setRenderHints(QPainter::RenderHints hints)

Sets the render hints used by the view to the specified hints.

Note: Setter function for property renderHints.

This function was introduced in Qt 4.8.

See also renderHints() and QPainter::setRenderHints().

QWebSettings *QGraphicsWebView::settings() const

Returns a pointer to the view/page specific settings object.

It is equivalent to

     view->page()->settings();

See also QWebSettings::globalSettings().

[override virtual] QSizeF QGraphicsWebView::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const

void QGraphicsWebView::triggerPageAction(QWebPage::WebAction action, bool checked = false)

Triggers the specified action. If it is a checkable action the specified checked state is assumed.

See also pageAction().

[override virtual] void QGraphicsWebView::updateGeometry()

[override virtual protected] void QGraphicsWebView::wheelEvent(QGraphicsSceneWheelEvent *ev)