Skip to content

Commit 9cd612e

Browse files
committed
Add QmlStackView
1 parent 5077379 commit 9cd612e

File tree

10 files changed

+251
-1
lines changed

10 files changed

+251
-1
lines changed

QmlStackView/Page1.qml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*!
2+
*@file Page1.qml
3+
*@brief Page1
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
import QtQuick 2.8
9+
import QtQuick.Controls 2.1
10+
11+
Page {
12+
id: frmWindow
13+
title: qsTr("设置")
14+
visible: true
15+
16+
property StackView stack: null
17+
18+
Button {
19+
height: 32
20+
width: 120
21+
text: "<-"
22+
anchors.left: parent.left
23+
anchors.top: parent.top
24+
onClicked: stack.pop()
25+
}
26+
27+
Label{
28+
id: label
29+
text: qsTr("设置")
30+
height: 80
31+
width: 240
32+
anchors.centerIn: parent
33+
font.pixelSize: 20
34+
}
35+
36+
Button {
37+
height: 32
38+
width: 120
39+
text: qsTr("个人设置")
40+
anchors.right: parent.right
41+
anchors.bottom: parent.bottom
42+
onClicked: {
43+
page2.visible = true;
44+
page2.stack = stack;
45+
stack.push(page2);
46+
}
47+
}
48+
49+
Page2 {
50+
id: page2
51+
visible: false
52+
}
53+
}

QmlStackView/Page2.qml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*!
2+
*@file Page2.qml
3+
*@brief Page2
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
import QtQuick 2.8
9+
import QtQuick.Controls 2.1
10+
11+
Page {
12+
id: frmWindow
13+
title: qsTr("个人设置")
14+
visible: true
15+
16+
property StackView stack: null
17+
18+
Button {
19+
height: 32
20+
width: 120
21+
text: "<-"
22+
anchors.left: parent.left
23+
anchors.top: parent.top
24+
onClicked: stack.pop()
25+
}
26+
27+
Label{
28+
id: label
29+
text: qsTr("个人设置")
30+
height: 80
31+
width: 240
32+
anchors.centerIn: parent
33+
font.pixelSize: 20
34+
}
35+
36+
Button {
37+
height: 32
38+
width: 120
39+
text: qsTr("帐号")
40+
anchors.right: parent.right
41+
anchors.bottom: parent.bottom
42+
onClicked: {
43+
page3.visible = true;
44+
page3.stack = stack;
45+
stack.push(page3);
46+
}
47+
}
48+
49+
Page3 {
50+
id: page3
51+
visible: false
52+
stack: stack
53+
}
54+
}

QmlStackView/Page3.qml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*!
2+
*@file Page3.qml
3+
*@brief Page3
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
import QtQuick 2.8
9+
import QtQuick.Controls 2.1
10+
11+
Page {
12+
id: frmWindow
13+
title: qsTr("帐号")
14+
visible: true
15+
16+
property StackView stack: null
17+
18+
Button {
19+
height: 32
20+
width: 120
21+
text: "<-"
22+
anchors.left: parent.left
23+
anchors.top: parent.top
24+
onClicked: stack.pop()
25+
}
26+
27+
Label{
28+
id: label
29+
text: qsTr("帐号")
30+
height: 80
31+
width: 240
32+
anchors.centerIn: parent
33+
font.pixelSize: 20
34+
}
35+
36+
Label{
37+
anchors.top: label.bottom
38+
anchors.horizontalCenter: parent.horizontalCenter
39+
text: qsTr("帐号信息")
40+
height: 80
41+
width: 240
42+
font.pixelSize: 20
43+
}
44+
}

QmlStackView/QmlStackView.pro

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#-------------------------------------------------
2+
#
3+
# Copyright (C) 2003-2103 CamelSoft Corporation
4+
#
5+
#-------------------------------------------------
6+
7+
QT += qml quick
8+
9+
CONFIG += c++11
10+
11+
SOURCES += main.cpp
12+
13+
RESOURCES += qml.qrc

QmlStackView/main.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*!
2+
*@file main.cpp
3+
*@brief 程序主文件
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
#include <QGuiApplication>
9+
#include <QQmlApplicationEngine>
10+
11+
int main(int argc, char *argv[])
12+
{
13+
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
14+
QGuiApplication app(argc, argv);
15+
16+
QQmlApplicationEngine engine;
17+
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
18+
19+
return app.exec();
20+
}

QmlStackView/main.qml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*!
2+
*@file main.qml
3+
*@brief 主文件
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
import QtQuick 2.8
9+
import QtQuick.Controls 2.1
10+
11+
ApplicationWindow {
12+
id: frmWindow
13+
title: qsTr("Qml堆栈窗体")
14+
width: 400
15+
height: 300
16+
visible: true
17+
18+
StackView {
19+
id: stack
20+
initialItem: mainView
21+
anchors.fill: parent
22+
}
23+
24+
Page {
25+
id: mainView
26+
27+
Label{
28+
text: qsTr("主页")
29+
height: 80
30+
width: 240
31+
anchors.centerIn: parent
32+
font.pixelSize: 20
33+
}
34+
Button {
35+
height: 32
36+
width: 120
37+
text: qsTr("设置")
38+
anchors.right: parent.right
39+
anchors.bottom: parent.bottom
40+
onClicked: {
41+
page1.visible = true;
42+
page1.stack = stack;
43+
stack.push(page1)
44+
}
45+
}
46+
}
47+
48+
Page1 {
49+
id: page1
50+
visible: false
51+
}
52+
}

QmlStackView/qml.qrc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<RCC>
2+
<qresource prefix="/">
3+
<file>main.qml</file>
4+
<file>Page1.qml</file>
5+
<file>Page2.qml</file>
6+
<file>Page3.qml</file>
7+
</qresource>
8+
</RCC>

QmlStackView/show.gif

185 KB
Loading

QtQuickExamples.pro

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ SUBDIRS += QmlCircular
1919
SUBDIRS += QmlRotationAnimation
2020
SUBDIRS += QmlShowSideWindow
2121
SUBDIRS += QmlSign
22-
SUBDIRS += QmlSlidingMenu
22+
SUBDIRS += QmlSlidingMenu
23+
SUBDIRS += QmlStackView

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,8 @@ QmlSlidingMenu: Qml侧边滑动菜单
8080

8181
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlSlidingMenu/show.gif?raw=true)
8282

83+
84+
QmlStackView: Qml堆栈窗体
85+
86+
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlStackView/show.gif?raw=true)
87+

0 commit comments

Comments
 (0)