qml之StackView

案例1:
import QtQuick 2.7
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
Window {
    id:root
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    StackView {
        id: stackView
        anchors.fill: parent
        initialItem: ListView {
            model: ListModel {
                ListElement {
                    title: "CircularGauge"
                }
                ListElement {
                    title: "DelayButton"
                }
                ListElement {
                    title: "Dial"
                }
                ListElement {
                    title: "Gauge"
                }
                ListElement {
                    title: "PieMenu"
                }
                ListElement {
                    title: "StatusIndicator"
                }
                ListElement {
                    title: "ToggleButton"
                }
                ListElement {
                    title: "Tumbler"
                }
            }
            delegate: Button {
                width: stackView.width
                height: root.height * 0.125
                text: title
                onClicked: {
                  Qt.quit();
                }
            }
        }
    }
}
案例2:
import QtQuick 2.7
import QtQuick.Window 2.2
import QtQuick.Controls 2.0//使用StackView必须引入
Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    StackView {
              id: stack
              initialItem: mainView
              anchors.fill: parent
          }
          Component {
              id: mainView
              Row {
                  spacing: 10//间距
                  Button {
                      text: "Push"
                      onClicked: stack.push(mainView)//前推进
                  }
                  Button {
                      text: "Pop"
                      enabled: stack.depth > 1//stack.dept记录数目
                      onClicked: stack.pop()//逆向推进
                  }
                  Text {
                      text: stack.depth//显示数目
                  }
              }
          }
}

 
  

你可能感兴趣的:(QT)