Qt Quick - StackLayout 堆布局
创始人
2024-06-02 18:39:32
0

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

相关内容

热门资讯

修复 爱普生 EPSON L4... L4151 L4153 L4156 L4158 L4163 L4165 L4166 L4168 L4...
【PdgCntEditor】解... 一、问题背景 大部分的图书对应的PDF,目录中的页码并非PDF中直接索引的页码...
监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
【前端】‘??‘与‘||‘有什... 0 问题 经常写const data = res.data.a ?? ''或者const d...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
牛客计算器的改良(Python... 文章目录1.题目描述2.输入描述:3.输出描述:4.示例15.分析6.代码7.结语 链接࿱...
正大杯|市调大赛|2023备赛... 关键信息 同时随着精细化养宠趋势的深入,宠物消费类目日渐丰富。 本报告通过 Niuco...
QGIS下载在线地图(Goog... 前言 国内外有很多在线地图下载软件,但功能单一,基本上只能下载数据&#x...