WebEngineHistory QML Type

Provides data models that represent the history of a web engine page. More...

Import Statement: import QtWebEngine 1.2
Since: QtWebEngine 1.1

Properties

  • backItems : QQuickWebEngineHistoryListModel
  • forwardItems : QQuickWebEngineHistoryListModel
  • items : QQuickWebEngineHistoryListModel

Detailed Description

The WebEngineHistory type can be accessed by using the WebEngineView.navigationHistory property.

The WebEngineHistory type providess the following WebEngineHistoryListModel data model objects:

  • backItems, which contains the URLs of visited pages.
  • forwardItems, which contains the URLs of the pages that were visited after visiting the current page.
  • items, which contains the URLs of the back and forward items, as well as the URL of the current page.

The easiest way to use these models is to use them in a ListView as illustrated by the following code snippet:


  ListView {
      id: historyItemsList
      anchors.fill: parent
      model: webEngineView.navigationHistory.items
      delegate:
          Text {
              color: "black"
              text: model.title + " - " + model.url + " (" + model.offset + ")"
          }
  }

The ListView shows the content of the corresponding model. The delegate is responsible for the format of the list items. The appearance of each item of the list in the delegate can be defined separately (it is not web engine specific).

The model roles title and url specify the title and URL of the visited page. The offset role specifies the position of the page in respect to the current page (0). A positive number indicates that the page was visited after the current page, whereas a negative number indicates that the page was visited before the current page.

The data models can also be used to create a menu, as illustrated by the following code snippet:


      toolBar: ToolBar {
          id: navigationBar
              RowLayout {
                  anchors.fill: parent;
                  ToolButton {
                      enabled: currentWebView && (currentWebView.canGoBack || currentWebView.canGoForward)
                      menu:Menu {
                          id: historyMenu

                          Instantiator {
                              model: currentWebView && currentWebView.navigationHistory.items
                              MenuItem {
                                  text: model.title
                                  onTriggered: currentWebView.goBackOrForward(model.offset)
                                  checkable: !enabled
                                  checked: !enabled
                                  enabled: model.offset
                              }

                              onObjectAdded: historyMenu.insertItem(index, object)
                              onObjectRemoved: historyMenu.removeItem(object)
                          }
                      }
                  }

For the complete example, see WebEngine Quick Nano Browser.

See also WebEngineHistoryListModel.

Property Documentation

[read-only] backItems : QQuickWebEngineHistoryListModel

URLs of visited pages.

This QML property was introduced in QtWebEngine 1.1.


[read-only] forwardItems : QQuickWebEngineHistoryListModel

URLs of the pages that were visited after visiting the current page.

This QML property was introduced in QtWebEngine 1.1.


[read-only] items : QQuickWebEngineHistoryListModel

URLs of back items, forward items, and the current item in the history.

This QML property was introduced in QtWebEngine 1.1.