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

Qt Quick - StackLayout 堆布局

StackLayout 堆布局

  • 一、概述
  • 二、attached 属性
  • 三、例子
    • 1. 按钮切换 StackLayout 页面

一、概述

StackLayout 其实就是说,在同一个时刻里面,只有一个页面是展示出来的,类似QStackWidget 的功能,主要就是切换界面的功能。这个类型我们可以通过设置currentIndex属性来修改当前可见的项。索引对应于StackLayout子元素的顺序。

StackLayout切换界面

与大多数其他布局不同,子项的Layout.fillWidth 和Layout.fillHeight 属性默认是被设置为true,因此,默认情况下,子项的填充大小与StackLayout的大小相同,只要它们的布局相同。最大宽度或布局。maximumHeight不会阻止它。

通过重新将项目添加到布局中来将项目添加到布局中。类似地,删除是通过从布局中重新父元素来完成的。这两个操作都会影响布局的count属性。

二、attached 属性

StackLayout 支持下面这些属性,但是我们一般不会去动的,而且这个类型是没提到外边距 margin的属性,就不去设置啦

  • Layout.minimumWidth
  • Layout.minimumHeight
  • Layout.preferredWidth
  • Layout.preferredHeight
  • Layout.maximumWidth
  • Layout.maximumHeight
  • Layout.fillWidth
  • Layout.fillHeight

三、例子

1. 按钮切换 StackLayout 页面

在这里插入图片描述

import QtQuick 2.0
import QtQuick.Layouts 1.3
import QtQuick.Window 2.3
import QtQuick.Controls 2.5Window {id: rootvisible: truewidth: 319height: 570title: qsTr("Hello World")ColumnLayout{anchors.fill: parentRowLayout{Layout.alignment: Qt.AlignHCenterButton{text: "首页"Layout.alignment: Qt.AlignHCenteronClicked:{stackWig.currentIndex = 0;}}Button{text: "联系"Layout.alignment: Qt.AlignHCenteronClicked:{stackWig.currentIndex = 1;}}}StackLayout{id:stackWigcurrentIndex: 0Rectangle{color: "#00B000"Text {id: homePagetext: qsTr("首页")anchors.verticalCenter: parent.verticalCenteranchors.horizontalCenter: parent.horizontalCenterverticalAlignment: Text.AlignVCenterhorizontalAlignment: Qt.AlignHCenter}}Rectangle{id: rectanglecolor: "steelblue"Text {id: contactPagetext: qsTr("联系")anchors.verticalCenter: parent.verticalCenteranchors.horizontalCenter: parent.horizontalCenterverticalAlignment: Text.AlignVCenterhorizontalAlignment: Qt.AlignHCenter}}}}
}
http://www.lryc.cn/news/39684.html

相关文章:

  • C/C++网络编程笔记Socket
  • RK3568平台开发系列讲解(网络篇)什么是Socket套接字
  • 2022年全国职业院校技能大赛(中职组)网络安全竞赛试题——渗透测试解析(详细)
  • 尚融宝03-mybatis-plus基本CRUD和常用注解
  • vue多行显示文字展开
  • SpringBoot:SpringBoot 的底层运行原理解析
  • 哪些场景会产生OOM?怎么解决?
  • 金三银四、金九银十 面试宝典 Spring、MyBatis、SpringMVC面试题 超级无敌全的面试题汇总(超万字的面试题,让你的SSM框架无可挑剔)
  • JAVA开发(Spring框架详解)
  • 自学大数据第八天~HDFS命令(二)
  • 贪心算法(几种常规样例)
  • 【数据结构】基础知识总结
  • 宣布推出 .NET 社区工具包 8.1!
  • ChatGPT解开了我一直以来对自动化测试的疑惑
  • 十大经典排序算法(上)
  • 如何从 MySQL 读取 100w 数据进行处理
  • 【数据降维-第2篇】核主成分分析(KPCA)快速理解,及MATLAB实现
  • Python+ChatGPT实战之进行游戏运营数据分析
  • Java每日一练(20230313)
  • 国内ChatGPT日趋成熟后,可以优先解决的几个日常小问题
  • 业内人士真心话,软件测试是没有前途的,我慌了......
  • 哈佛与冯诺依曼结构
  • 传输安全HTTPS
  • Docker--(六)--Docker资源限制
  • 消息队列总结及案例
  • 通过WiFi连接adb调试
  • 【蓝桥杯-筑基篇】常用API 运用(1)
  • 想要成为高级网络工程师,只需要具备这几点
  • c++ 每日十问3-处理数据
  • 【MySQL】实验一 数据定义