Qml:布局

简介: Qml:布局
import QtQuick
import QtQuick.Window
import QtQuick.Layouts
Window
{
    width: 1280
    height: 800
    visible: true
    title: qsTr("Test Layout")
    Rectangle
    {
        id:colroot
        implicitWidth: 300
        implicitHeight: 400
        color: "#EEEEEE"
        ColumnLayout
        {
            anchors.fill: parent
            spacing: 2
            Rectangle
            {
                color:"pink"
                Layout.minimumHeight: 40
                Layout.maximumHeight: 200
                Layout.maximumWidth: 300
                Layout.fillWidth: true
                Layout.fillHeight: true
                Text{anchors.centerIn: parent; text:parent.width +"x"+parent.height}
                MouseArea
                {
                    anchors.fill: parent
                    onClicked:
                    {
                        colroot.width+=10
                        colroot.height+=10
                    }
                }
            }
            Rectangle
            {
                color:"plum"
                Layout.fillWidth: true
                Layout.preferredHeight: 40
                Text{anchors.centerIn: parent; text:parent.width +"x"+parent.height}
                MouseArea
                {
                    anchors.fill: parent
                    onClicked:
                    {
                        colroot.width-=10
                        colroot.height-=10
                    }
                }
            }
            Rectangle
            {
                color:"lightgreen"
                Layout.preferredWidth: 100
                Layout.preferredHeight: 40
                Text{anchors.centerIn: parent; text:parent.width +"x"+parent.height}
            }
        }//ColumnLayout
        Text{text:"ColumnLayout"}
    }//colroot
    Rectangle
    {
        x:310
        id:rowroot
        implicitWidth: 600
        implicitHeight: 400
        color: "#EEEEEE"
        RowLayout
        {
            id:row
            anchors.fill: parent
            spacing: 0  //去掉间隔
            Rectangle
            {
                color:"pink"
                Layout.preferredWidth: 100
                Layout.fillHeight:true
                //放大背景
                MouseArea
                {
                    anchors.fill: parent
                    onClicked:
                    {
                        rowroot.width+=10
                        rowroot.height+=10
                    }
                }
                Text{anchors.centerIn: parent; text:parent.width +"x"+parent.height}
            }
            Rectangle
            {
                color:"lightgreen"
                Layout.fillWidth:true
                Layout.fillHeight:true
                Layout.minimumHeight: 100
                Layout.minimumWidth: 200
                MouseArea
                {
                    anchors.fill: parent
                    onClicked:
                    {
                        row.layoutDirection = (row.layoutDirection +1)%2
                    }
                }
                Text{anchors.centerIn: parent; text:parent.width +"x"+parent.height}
            }
            Rectangle
            {
                color:"plum"
                Layout.alignment: Qt.AlignRight //右对齐
                Layout.preferredWidth: 100
                Layout.fillHeight:true
                //缩小背景
                MouseArea
                {
                    anchors.fill: parent
                    onClicked:
                    {
                        rowroot.width-=10
                        rowroot.height-=10
                    }
                }
                Text{anchors.centerIn: parent; text:parent.width +"x"+parent.height}
            }
        }
        Text{text:"RowLayout"}
    }
    Rectangle
    {
        y:410
        id:gridroot
        implicitWidth: 300
        implicitHeight: 300
        color: "#EEEEEE"
        GridLayout
        {
            columns:3
            rowSpacing:0
            columnSpacing: 0
            //3X3
            Repeater
            {
                model:9
                Rectangle
                {
                    implicitWidth: 100
                    implicitHeight: 100
                    color: "lightgreen"
                    border.color: "pink"
                    border.width: 1
                }
            }
        }//GridLayout
        Text{text:"GridLayout"}
    }//gridroot
    Rectangle
    {
        x:310
        y:410
        id:stackroot
        implicitWidth: 300
        implicitHeight: 300
        color: "#EEEEEE"
        StackLayout
        {
            id:stack
            anchors.fill: parent
            currentIndex: 0 //当前显示哪个界面 从0开始
            Rectangle
            {
                color:"pink"
                Text{anchors.centerIn: parent; text:parent.width +"x"+parent.height}
            }
            Rectangle
            {
                color:"lightgreen"
                Text{anchors.centerIn: parent; text:parent.width +"x"+parent.height}
            }
            Rectangle
            {
                color:"lightblue"
                Text{anchors.centerIn: parent; text:parent.width +"x"+parent.height}
            }
        }//StackLayout
        MouseArea
        {
            anchors.fill: parent
            onClicked:
            {
                stack.currentIndex = (stack.currentIndex+1) % stack.count
            }
        }
    }//stackroot
}


相关文章
|
存储
【模型预测控制】Matlab自带MPC Designer工具(自用)
【模型预测控制】Matlab自带MPC Designer工具(自用)
1860 0
|
11月前
|
SQL 安全 数据库
GoWind Admin|风行 — 开箱即用的企业级全栈中后台框架:数据权限体系设计与实现
GoWind Admin(风行)是开箱即用的企业级全栈中后台框架,内置五层数据权限体系:租户隔离、业务单元、行级、列级、操作/状态级,支持多租户、ABAC动态策略与非侵入式DataScope引擎,实现安全合规、灵活可扩展的权限管理。(239字)
1695 2
|
12月前
|
消息中间件 Java Nacos
SpringCloud概述
Spring Cloud是微服务的统一解决方案,具备注解化、组件丰富、开箱即用等特点。其版本以地铁站命名,避免与子项目冲突。Spring Cloud Alibaba整合Nacos、Sentinel、Seata等阿里开源组件,提供更完整、稳定的微服务生态,成为当前主流技术选型。
|
机器学习/深度学习 自然语言处理 算法
文心4.5系列模型,正式开源!
6月30日,百度文心大模型4.5正式开源,魔搭社区在开源首日快速接入文心大模型,提供真正可用、好用、可落地的大模型解决方案,现已面向广大企业、开发者下载体验!
1006 1
|
消息中间件 存储 监控
消息队列通信的优缺点
【10月更文挑战第29天】消息队列通信具有诸多优点,如解耦性强、异步通信、缓冲削峰等,能够有效地提高系统的灵活性、可扩展性和稳定性。但同时也存在一些缺点,如系统复杂性增加、性能开销、数据一致性挑战和实时性受限等。在实际应用中,需要根据具体的业务需求和场景,权衡其优缺点,合理地选择和使用消息队列通信机制,以实现系统的高效运行和优化。
|
Cloud Native
云原生架构之X无限延伸:跨AZ、跨Region、跨Cloud,一文让你彻底解锁!
【8月更文挑战第25天】在云原生架构中,可扩展性至关重要,它确保了应用能按需高效调整资源。本文聚焦于三种扩展策略:跨AZ、跨Region及跨云扩展。跨AZ扩展通过在同一云内部不同可用区间部署应用副本增强容错性;跨Region扩展则通过不同地理区域的应用副本部署提升全球访问性能与可靠性;而跨云扩展则利用多云环境进一步加强应用的弹性和覆盖范围。文中提供了基于AWS CloudFormation的具体实践示例,帮助读者深入理解这些扩展机制的实际应用。
1181 2
|
开发工具 git 索引
repo sync 更新源码 android-12.0.0_r34, fatal: 不能重置索引文件至版本 ‘v2.27^0‘。
本文描述了在更新AOSP 12源码时遇到的repo同步错误,并提供了通过手动git pull更新repo工具来解决这一问题的方法。
1098 1
|
人工智能 自然语言处理 安全
黑客工具WormGPT:生成式AI的黑暗双胞胎
【2月更文挑战第12天】黑客工具WormGPT:生成式AI的黑暗双胞胎
1123 5
黑客工具WormGPT:生成式AI的黑暗双胞胎
|
SQL Linux 数据库
Linux上sqlite的安装和使用方法以及在QT中如何使用sqlite&笔记总结
Linux上sqlite的安装和使用方法以及在QT中如何使用sqlite&笔记总结
|
安全 前端开发 开发工具
什么是APP封装?流程和实现方式是什么,有什么优势?
APP封装是将应用程序的代码、资源和依赖项打包成一个可执行的文件或安装包的过程。封装过程中,将应用的代码、资源和依赖项进行整合,并生成一个独立的安装包,用户只需下载并安装该包即可使用应用。
687 3