Solved How to enter different StackViews
-
Hy @all
I have a question about the navigation with StackViews and SwipeViews. On the following image (http://imgur.com/a/q8JAw) you can see the structure of my project. There's the main.qml which contains the "main" StackView. This Stackview has two children, the mainPage.qml and the additionalPage.qml. In this pages there are also some StackViews/SwipeViews, I think it's easy to unterstand when you are looking at the picture. Okay, so if I'm in the SwipeView of the mainPage.qml (DashPage for example) and now I want to jump to, let's say settingsPage.qml which is a children of the StackView in additionalPage.qml. How am I able to do this?
I can't call the StackView via "Id" from the mainPage.qml. How can I solve this?Thanks in advance!
Link to the image
http://imgur.com/a/q8JAw -
Declare some singals in your qmls and react to them in main.qml
e.g in mainPage.qml:
signal jumpToSettings()
and emit it when ever needed.
In main.qml add a singal handler to the mainPage object like:
onJumpToSettings(): { //stack.push() ... }
-
@sneubert said in How to enter different StackViews:
Declare some singals in your qmls and react to them in main.qml
e.g in mainPage.qml:
signal jumpToSettings()
and emit it when ever needed.
In main.qml add a singal handler to the mainPage object like:
onJumpToSettings(): { //stack.push() ... }
and how can I access the StackView in additionalPage.qml when I'm in main.qml?
-
declare a function like
function showSettings()
in additionalPage.qml, where you push the settingsPage in additionalPage StackView. in main.qml signal handler you can thenonJumpToSettings: { mainStackView.push(additionalPage); additionalPage.showSettings(); }
-
@sneubert said in How to enter different StackViews:
declare a function like
function showSettings()
in additionalPage.qml, where you push the settingsPage in additionalPage StackView. in main.qml signal handler you can thenonJumpToSettings: { mainStackView.push(additionalPage); additionalPage.showSettings(); }
ah, so the syntax to access the function is nameOfQMLFile**.**something.
but I can only access the functions of the root item in a qml file right? -
So, basically your question isn't about stack view or swipe view at all, but about how to access inner components when they are in their own files and not directly visible outside? Basically you have to travel through the hierarchy and delegate the access in one way or another as many times/levels as needed. Functions, as sneubert told above, are one way. Another way is to use properties and aliases. You can make inner component visible outside by declaring alias for it. Then you can access all properties of that exposed component. Or you can declare extra property in outer component and create a binding so that inner component's property is bind to outer component's property value. So basically with properties there are two ways:
- From outside handle an inner component directly by making it visible (recursively).
- From outside change a property value of the top level component so that it's propagated downwards to inner component (recursively).
If you have structure A { B { C{}} but each are in their own files and A can't see C, either you make C visible to A through B by declaring an alias for C in B, or you make a simple property in B and bind the wanted property in C to it.
If you have A, B, C, D and so on your have to add more levels of propagation.
I think this is one of the more tedious features of QML. If you have stucture A { B { C{}} in one file you can easily access C's properties from A, but if you make C a component you have to write extra code. If you want to customize one value in a Quick Component, you have to write it all instead of just changing that value. You just have to learn to live with it.
-
@Eeli-K said in How to enter different StackViews:
So, basically your question isn't about stack view or swipe view at all, but about how to access inner components when they are in their own files and not directly visible outside? Basically you have to travel through the hierarchy and delegate the access in one way or another as many times/levels as needed. Functions, as sneubert told above, are one way. Another way is to use properties and aliases. You can make inner component visible outside by declaring alias for it. Then you can access all properties of that exposed component. Or you can declare extra property in outer component and create a binding so that inner component's property is bind to outer component's property value. So basically with properties there are two ways:
- From outside handle an inner component directly by making it visible (recursively).
- From outside change a property value of the top level component so that it's propagated downwards to inner component (recursively).
If you have structure A { B { C{}} but each are in their own files and A can't see C, either you make C visible to A through B by declaring an alias for C in B, or you make a simple property in B and bind the wanted property in C to it.
If you have A, B, C, D and so on your have to add more levels of propagation.
I think this is one of the more tedious features of QML. If you have stucture A { B { C{}} in one file you can easily access C's properties from A, but if you make C a component you have to write extra code. If you want to customize one value in a Quick Component, you have to write it all instead of just changing that value. You just have to learn to live with it.
Thanks, this helped a lot and was the crunchpoint of my problem.