Page rows and page stacks

Add flow to your application: Add, remove and replace pages in different ways

A row of pages

We have seen so far that one of the core components of a Kirigami window is a Kirigami.Pagearrow-up-right. A single page can envelop the whole screen of the application, or it can be shown together with other pages at the same time, if there is space.

Whenever a page gets added, or pushed, it appears to the right of the existing page(s), forming a row. This row of pages can be managed with the fittingly named Kirigami.PageRowarrow-up-right.

A minimal page row with a single page could look like this:

import QtQuick
import org.kde.kirigami as Kirigami

Kirigami.ApplicationWindow {
    title: "Single Page"
    width: 500
    height: 200

    Kirigami.PageRow {
        anchors.fill: parent

        Kirigami.Page {
            id: mainPage
            anchors.fill: parent
            Rectangle {
                anchors.fill: parent
                color: "lightblue"
            }
        }
    }
}
A single page with light blue color to show the page's dimensions

There are two improvements that can be done here. The first is that, with initialPagearrow-up-right, we can both set mainPage to be the first page that appears in the page row, and have its dimensions be managed by the page row instead of via manual anchorsarrow-up-right, positionersarrow-up-right or layoutsarrow-up-right. The second is to have a toolbar, which can be set by defining a toolbar style with globalToolBar.stylearrow-up-right. There are a few styles we can choose from, but we'll go with Kirigami.ApplicationHeaderStyle.Autoarrow-up-right for now.

A single page with toolbar and light blue color to show the page's dimensions

There are only two ways of adding pages to a page row: by setting its initialPagearrow-up-right (which can optionally take an array of pages) or by using push()arrow-up-right. To delete a page from the page row, you should use pop()arrow-up-right, whereas goBack()arrow-up-right or goForward()arrow-up-right can be used to navigate between pages.

Initial page with light blue color
Upon clicking Push

The application's stack of pages

If a Kirigami.PageRowarrow-up-right with a toolbar looks familiar to you, that is because you have seen it before. An ApplicationWindow.pageStackarrow-up-right is nothing more than a very convenient, global page row. Every function available to a PageRow is also available to the pageStack.

The previous example can be reduced significantly with a pageStack, with the added bonus of navigation actions:

In general you'll want to use a pageStack rather than implement your own PageRowarrow-up-right, especially when your application gets bigger and you need your components living in separate files. If you create your window in your Main.qml using a Kirigami.ApplicationWindowarrow-up-right, a component residing in another file can still directly invoke the global pageStack by means of a call to the applicationWindow()arrow-up-right:

and

Clicking the button pushes a new page with help of applicationWindow

Last updated