当前位置: 首页> 教育> 高考 > Qt/QML学习-StackView

Qt/QML学习-StackView

时间:2025/7/12 2:39:20来源:https://blog.csdn.net/qq1138345424/article/details/141272694 浏览次数:1次

QML学习

  • StackView例程
  • 视频讲解
  • 代码

main.qml

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15Window {width: 640height: 480visible: truetitle: qsTr("StackView")StackView {id: stackViewanchors.fill: parent// 背景视图background: Rectangle{color: "green"}// 启动视图initialItem: MyView01 {stackView: stackView}// 过渡动画pushEnter: Transition {from: "*"to: "*"PropertyAnimation {property: "width"from: 0to: stackView.widthduration: 500}PropertyAnimation {property: "height"from: 0to: stackView.heightduration: 500}}}
}

MyView01.qml

import QtQuick 2.15
import QtQuick.Controls 2.15Item {property StackView stackViewRectangle {anchors.fill: parentcolor: "red"Text {anchors.centerIn: parenttext: "视图1"font.pointSize: 30}Button {anchors.right: parent.rightfont.pointSize: 20text: "进入视图2"onClicked: {stackView.push("qrc:/MyView02.qml",{stackView: stackView})}}}
}

MyView02.qml

import QtQuick 2.15
import QtQuick.Controls 2.15Item {property StackView stackViewRectangle {anchors.fill: parentcolor: "yellow"Text {anchors.centerIn: parenttext: "视图2"font.pointSize: 30}Button {font.pointSize: 20text: "回退视图1"onClicked: {stackView.pop()}}Button {anchors.right: parent.rightfont.pointSize: 20text: "进入视图3"onClicked: {stackView.push("qrc:/MyView03.qml",{stackView: stackView})}}}
}

MyView03.qml

import QtQuick 2.15
import QtQuick.Controls 2.15Item {property StackView stackViewRectangle {anchors.fill: parentcolor: "blue"Text {anchors.centerIn: parenttext: "视图3"font.pointSize: 30}Button {font.pointSize: 20text: "回退视图2"onClicked: {stackView.pop()}}Button {anchors.right: parent.rightfont.pointSize: 20text: "回退首页"onClicked: {stackView.pop(null)}}}
}

演示

视频讲解

关键字:Qt/QML学习-StackView

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: