0

I have some 3 Components inside the StackView QML type and I am able to change the views using push() and pop(). Further down, I would like to update UI(Component) based on user configurations when I push() or pop() to that UI. Going through the documentation, I found Stack.status interesting in this case, but have no idea how to use it.

Can anyone give some example regarding it?

Below is the code how I load my screens into the stack view and navigate:

StackView {
    id: stackView
    visible: false
    //        rotation: 180
    anchors.fill: parent

    initialItem: componentHome

    Component.onCompleted:
    {

    }

}
Component
{
    id: componentHome
    Home
    {
        //This is how I traverse the screens
        onMenuClicked:
        {
            console.log("opening "+name+" screen")
            if(name === "settings")
            {
                //Here, for eg. how to update UI in Settings screen before pushing it?
                stackView.push(componentSettings)
            }
        }
    }
}
Component
{
    id: componentSettings
    Settings
    {
    }
}
Component
{
    id: componentPlay
    Play
    {
    }
}
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
jxgn
  • 741
  • 2
  • 15
  • 36

2 Answers2

0

I would do that in the following way:

import QtQuick.Controls 2.1

StackView {
    id: stack
    anchors.fill: parent
    initialItem: page1
}

Button {
    text: "add page"
    onClicked: {
        var page = stack.push(page2, {color: "red"});
        //page.color = "red"; // - that also should work
    }
}

Component {
    id: page1
    Rectangle {
        color: "black"
    }
}

Component {
    id: page2
    Rectangle {
        color: "black"
    }
}
folibis
  • 12,048
  • 6
  • 54
  • 97
0

Using StackView.onStatusChanged: into components should help you, but be carefully - you cannot define was your component popped or another component was pushed above it by StackView.status (at least is was so about a year ago, I can't check how it is right now). Some detail you can find in small discussion in my old question

aknew
  • 1,101
  • 7
  • 23