Luca
Luca

Reputation: 10996

Resetting a QML StackView to initial state

I have a QML StackView which during the application has many components being pushed to it. What I would like to do is actually reset the StackViewto its initial state at some point during the application. The StackView is defined as:

StackView {
    id: soemID
    initialItem: myItem
}

As the application goes on things get pushed and popped. I looked for some convenient way to reset this to only hold the initial item but could not find it. Is the only way to do this would be to successively pop the items till only one item remains?

Upvotes: 3

Views: 2922

Answers (2)

Volodymyr K.
Volodymyr K.

Reputation: 679

soemID.pop(null) 

should do the trick. From StackView documentation:

Item pop(Item item = undefined)

If item is null, all items down to (but not including) the first item will be popped. If not specified, only the current item will be popped....

Upvotes: 7

Luca
Luca

Reputation: 10996

As suggested by the comment, clearing the stack and then pushing the initial item did the trick.

soemID.clear()
soemID.push(soemID.initialItem)

Upvotes: 4

Related Questions