QtQuick堆栈窗口

这个好像在之前的版本就有了,QtQuick的堆栈窗口 depth表示当前堆栈中的窗口数量,每一个窗口可以是一个自定义组件 也可以是一个url。push添加新窗口,pop返回上层。在AppXXXWindow下,顶部导航会遮挡堆栈窗口。因此要写逻辑隐藏,他有一个initialItem属性,是默认的第一个堆栈窗口,也就是顶层窗口。每一个push的窗口有自己的内存,不会因为push相同的id而造成数据混乱
ApplicationWindow {
    id:root
    visible: true;
    height: 480;
    width: 320;
    property real pixelDensity: 4.46
    property real multiplierH: root.height/480 //default multiplier, but can be changed by user
     property real multiplierW: root.width/320 //default multiplier, but can be changed by user
    function dpH(numbers) {

        return Math.round(numbers*((pixelDensity*25.4)/160)*multiplierH);
    }
    function dpW(numbers) {

        return Math.round(numbers*((pixelDensity*25.4)/160)*multiplierW);
    }
    property color  accentcol:"red"
    property color  backgroundcol:"white"
    property color  foregroundcol:"#000000"
    property color  primarycol:"blue"
    Material.accent:accentcol
    Material.background:backgroundcol
    Material.foreground:foregroundcol
    Material.primary: primarycol

        header: ToolBar{
            id:hd;
            visible: stackView.depth>1?false:true

            height: stackView.depth>1?0:dpH(72)
                Text{
                    text:"hello";
                    anchors.centerIn: parent
                    color: "white";
                }
            }

        SwipeView{
            id:sw;
            anchors.fill: parent;
            currentIndex: footertabBar.currentIndex;
            Page1{

            }
            Item{
            StackView {
                property int  cur: 0;
                id: stackView;

                anchors.fill: parent

                initialItem: Pane {
                    id: pane
                    padding: 10
                    ColumnLayout{
                        Label{
                            text:stackView.cur ;
                        }

                        Button{
                            text:"push";
                            onClicked: { 
                                stackView.push(subpage)
                            }
                        }
                    }


                }
            }
        }
}

Component{
    id:subpage;

    Item{
        ToolBar{
            id:bar;
         width: root.width;
         anchors.top: root.top
         height: dpH(72)
         Row{
             id:row;
            anchors.fill: parent
             Text{
                 height: parent.height;
                 text:"<----";
                 verticalAlignment: Text.AlignVCenter

                 anchors.verticalCenter : parent.verticalCenter
                 color: "white";
                 MouseArea{
                     anchors.fill: parent;
                     onClicked: {
                         stackView.depth;
                         stackView.pop();
                     }
                 }
             }

             Text{
                 text:"当前序号:"+stackView.depth;
                 anchors.centerIn: parent
                 color: "white";
             }

             Text{
                 height: parent.height;
                 text:"---->";
                 verticalAlignment: Text.AlignVCenter

                 anchors.verticalCenter : parent.verticalCenter
                 anchors.right: parent.right
                 color: "white";
                 MouseArea{
                     anchors.fill: parent;
                     onClicked: {
                         stackView.push(subpage)

                     }
                 }
             }

         }


         }
        ColumnLayout{
            anchors.top:bar.bottom
            width: parent.width
            height: parent.height
            Rectangle{
                anchors.fill: parent;
                color:Qt.rgba( Math.random(255),
                               Math.random(255),
                               Math.random(255),
                               Math.random(255));
            }


        }
    }
}
    footer: TabBar {
        id: footertabBar
      currentIndex: sw.currentIndex
        TabButton {

            text: qsTr("footer Tab1");
        }

        TabButton {
            text: qsTr("footer Tab2")
        }
        TabButton {
            text: qsTr("footer Tab3")
        }

    }
}

这里写图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值