当前位置: 首页 > news >正文

Qt/QML学习-StackView

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)}}}
}

演示

视频讲解


http://www.mrgr.cn/news/445.html

相关文章:

  • 【笔试题面试题】(网络编程类1)知识点汇总,常用概念
  • Vue 3 + 天地图 + D3.js 绘制行政区划
  • 4.vue中引入axios
  • 关于鸿蒙开发中装饰器@Extend、@Styles、@Builder的介绍
  • Linux - 权限
  • PostgreSQL的walwriter进程
  • 【SpringBoot】SpringBoot项目中实现数据缓存
  • 家里养有宠物,宠物空气净化器真的能除毛除臭吗?
  • 使用PowerShell自动化Windows系统管理任务
  • Squish 8.0现已发布
  • 用“文心一言”写的文章,看看AI写得怎么样?
  • PHP中英文企业官网系统应用插件
  • pyexiv2库 EXIF信息读取、写入
  • FFmpeg源码:av_log2函数分析
  • Redis缓存——缓存更新策略和常见的缓存问题
  • JVM的组成
  • 用Python实现9大回归算法详解——01. 线形回归算法
  • 《书生大模型实战营第3期》进阶岛 第4关: InternVL 多模态模型部署微调实践
  • 解析网络流量管理方案:简化基于云的DNS负载均衡
  • 贷齐乐案例