C++ 入門指南 4.01
練習 26.8 參考程式 - 練習 QML 的 StackView
import QtQuick
import QtQuick.Controls
ApplicationWindow {
title: qsTr("計數器")
width: 400
height: 280
visible: true
StackView {
id: stack
initialItem: mainView
anchors.fill: parent
}
Component {
id: mainView
Column {
width: 400
height: 280
Row {
width: 400
height: 200
Button {
width: 200
height: 200
text: qsTr("加一")
onClicked: stack.push(mainView)
}
Button {
width: 200
height: 200
text: qsTr("減一")
enabled: stack.depth > 1
onClicked: stack.pop()
}
}
Row {
width: 400
height: 80
Text {
anchors.centerIn: parent
font.pointSize: 40
text: stack.depth
}
}
}
}
}
/* 《程式語言教學誌》的範例程式
http://kaiching.org/
檔名:main.qml
功能:示範 Stack 型態
作者:張凱慶 */
回到練習題目