Creating a Multi-Page QML Application with StackView and Dynamic Titles

This tutorial gives you some perspective about how to use StackView to navigate between pages with dynamic titles. You can find the complete project here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import QtQuick
import QtQuick.Controls

ApplicationWindow {
//title: currentItem.title
width: 640
height: 480
visible: true

StackView {
id: stackView
initialItem: mainPage
anchors.fill: parent
onCurrentItemChanged: {
title = currentItem.title;
}
}

Component {
id: mainPage

Page {
title: qsTr("Main Page")

Column {

Button {
text: "Push Page 1"
onClicked: stackView.push(page1)
}

Button {
text: "Push Page 2"
onClicked: stackView.push(page2)
}
}
}
}

Component {
id: page1

Page {
title: "Page 1"

Button {
text: "Pop"
onClicked: stackView.pop()
}
}
}

Component {
id: page2

Page {
title: qsTr("Page 2")

Button {
text: "Pop"
onClicked: stackView.pop()
}
}
}
}

Author

Kelvin Cervan

Posted on

2024-12-10

Updated on

2024-12-15

Licensed under