How to Identify an Item which i am going to push in stackview is already existed in stackview's stack ?



  • Hi All,
    assume that i have multiple "page" items and a "StackView" as shown below.
    i want to achieve something like , if i have already pushed 'page1' and if i have to push it one more time i have to search weather this particular 'page' already existed in the "StackView" tree ,if it is there i want to make that particular Item as top item in "StackView",if it is not there i will push that particular "page"
    How i can achieve this ??

    Component{
          id:page1
          Page{........}
    }
    Component{
          id:page2
          Page{........}
    }
    Component{
          id:page3
          Page{........}
    }
    StackView
    {
    id:sv
    initialItem: page1
    
    }
    


  • Hi,
    @divaindie said in How to Identify an Item which i am going to push in stackview is already existed in stackview's stack ?:

    achieve

    ApplicationWindow {
        id: window
        visible: true
        width: 600
        height: 200
        Component{
            id:page1
            Rectangle{
                color: "red"
            }
        }
        Component{
            id:page2
            Rectangle{
                color: "green"
            }
        }
        Component{
            id:page3
            Rectangle{
                color:"blue"
            }
        }
        property variant  pages : [page1,page2,page3]
    
        function setMenu(ind){
            sv.push(pages[ind])
        }
    
        RowLayout{
            id:menuLayout
            Repeater{
                model: pages.length
                Button{
                    text: "menu " + index
                    onClicked: {
                        setMenu(index)
                    }
                }
            }
        }
    
        StackView
        {
            id:sv
            initialItem: page1
            anchors{
                top : menuLayout.bottom
                left:parent.left
                right:parent.right
                bottom:parent.bottom
            }
        }
    }
    

    @divaindie said in How to Identify an Item which i am going to push in stackview is already existed in stackview's stack ?:

    search weather this particular 'page' already existed in the "StackView" tree ,if it is there i want to make that particular Item as top item in "StackView",if it is not there i will push that particular "page"

    you don't have to handle this



  • thanks !!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.