Re: Change page content based on selected dropdown item

that's because sabdelsayed's code calls removeAll() and createObject() every time you switch the selected index. So it removes all visible elements and creates them completely new again every time (@sabdelsayed I don't think it's a good solution performancewise, also, if you assume that inside those containers any changes/settings were made, those changes/settings would be lost. Or if it would be a list/scrollview, the position would also be lost)

@macaronlover you can keep using that code, but what you should do is 1) not call removeAll()2) on creation completed, create your first container as default3) create a property variant in your Page definition, storing your containers after createObject. Then, inside onSelectedIndexChanged, check if the property was created already, if yes, set it to visible and all the others to invisible

Re: Change page content based on selected dropdown item

Acutally pyth, the ComponentDefinition component doesn't have a visible property and the code doesn't compile if the modifications you suggested are incorporated. The visible property exists only for ControlDelegate and Delegate.

@macaronlover, please use my modified (and not original), code where I have added functionality to remove and add components based on the user-selected option. You still need to add, however, code that initializes the view for the user.

Memorywise, the above code is good. Might be not the best though in terms of loading/unloading time. If that is a concern, then the best way to implement this is indeed using ControlDelegates based on Simon's suggestion.

For more details on the various ways to create QML dynamically checkout this documentation:

Re: Change page content based on selected dropdown item

creating stuff once and switching the visible flag is one solution.i would try to use ControlDelegates and setting them to active.

----------------------------------------------------------feel free to press the like button on the right side to thank the user that helped you.please mark posts as solved if you found a solution.@SimonHain on twitter

1) it compiles, because it is stored inside a variant (and QML doesn't care what type it is)

2)I never set a visible flag into a ComponentDefinition, but on that variant, which was created from a ComponentDefinition with a qml, which

3) must be a Container at root (you stated this yourself in your previous posts), and containers do have a visible property

Also, in your code, you still remove everything. If you assume that the user made any change (scrolling a list (position), setting a checkbox, entering some text inside a textfield), all these changes would be lost as soon as the user switches the index of the dropdown

@simon_hain your suggestion is even better, but I feared that macaronlover did not feel comfortable with ControlDelegates yet and wanted to give a simple working solution

-----------------------------------------------------------------------I'm a bird from outer space. But I'm not flappy o.o

if you want to keep user entries etc on the created elements you would best create stuff once and keep it referenced, toggling the visibility as suggested by pyth.

----------------------------------------------------------feel free to press the like button on the right side to thank the user that helped you.please mark posts as solved if you found a solution.@SimonHain on twitter