QML-StackView


import QtQuick.Controls 2.2
import QtQml 2.2
import QtQuick 2.9
ApplicationWindow {
    title: qsTr("Hello World")
    width: 640
    height: 480
    visible: true

    Row{
        id:row;
        width: parent.width;
        height: 40;
        Button {
            id:btn1;
            text: "1"
            onClicked: {
                stack.push(mainView);

            }
        }
        Button {
            id:btn2;
            text: "2"
            onClicked: {
               stack.push(gView);
            }
        }
    }



    StackView {
        id: stack
        width: parent.width;
        height: parent.height-row.height;
        anchors.top:row.bottom;
        Component.onCompleted: {
            stack.push(gView);
            stack.push(mainView);
        }
    }

    Component {
        id: mainView;
        Main_struct{}
    }
    Component {
        id: gView;
        MyGuid{}
    }

}

刪除、添加:

    function respondNodeClick(node_id)
    {
        if(100===node_id)//主頁
        {
           for(var i=stack.depth;i>1;i--)
            {
                stack.pop();
            }
        }
        else if(101===node_id)//返回
        {
            if(stack.depth > 1)
            {
               stack.pop();
            }
        }
        else if(5===node_id)//顯示頻綜/波形qml
        {
            stack.push(gView);
        }
    }

 

ps:

1、stackview是動態生成界面,如從1界面->2界面->1界面->2界面,2界面不會一直存在,而是被銷毀,最后一次進入2界面后,會再次生成2界面,所以這種方式不太適合實時監控的界面


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM