As @ddriver said, the advantage of using StackView
is that you don't have to do it all yourself. I doubt the performance benefit you get from not using StackView (if you get one at all) will outweigh the decline in readability of your code. If I had to maintain your code and saw that you were doing it yourself, the first question I'd ask is why you didn't just use StackView
.
- Transitions: you'd have to maintain animations for each page, which you get for free with
StackView
- as in, they exist by default and you don't have to write a single line of code to get a nice looking animation.
- Visibility: you'd probably have to have an index for each page and compare it against a
currentIndex
property in e.g. your main.qml
file. Give each "page" an index and set visible: index == currentIndex
for each item. You'd have to ensure that this happens after the animations (if you have any).
- Memory: The typical use case with
StackView
is to push Component
s from which items are instantiated and managed by StackView
. If you have a lot of complex pages, this could impact performance if you don't destroy them when they're not visible.
I could have for example a header, a main item (Item1) set to visible and a footer.
Page
and ApplicationWindow
have this functionality, too.
If you're doing it as a learning exercise, by all means play around with a custom implementation.
If you're aiming for a reliable (StackView
is auto-tested and exposed to the public) finished product, use StackView
.