Dynamic items adding to the Flow layout?
I need to create and add dynamically items to the Flow layout. Is it possible?
The example with positioners in QML only offers increasing and decreasing opacity of the existing items, thus creating the illusion of dynamic. That’s not really what I need.
10 replies
Nevermind, got it :D
Here is how it works:
- Flow {
- id: customTagPage
- width: mainScreen.width
- height: mainScreen.height
- }
- TextInput {
- id: customTagInput
- width: 150
- height: 40
- onAccepted: {
- if(tagComponent.status == Component.Ready) {
- var tagLabel = tagComponent.createObject(customTagPage);
- tagLabel.tagLabelText = customTagInput.text;
- }
- }
- }
It’s all dynamic now.
Delegates/models are quite easy to use and very powerful! They looked confusing at first to me but I realised that the delegate is just the object and the model is just the data.
As for adding animations, I made my own in a ListView – it’s also easy to do in QML :).
Strange that Flow has ‘add’ animations and yet no special function for adding children?
I always figured it was just a simpler (less overhead) layout item and that people would use GridView if they wanted dynamic.
What I like best about the code you gave is how easy it is to create completely different components (not just a single delegate) within the same item. I will definitely make use of that in future.
If you had the Component element defined in the same QML file, you could just use onAccepted: tagComponent.createObject(parent)
I saw Loader before and ignored it but thinking about it now, it’s probably the better (i.e. cleaner) solution.
- Flow {
- id: customTagPage
- width: mainScreen.width; height: mainScreen.height
- }
- TextInput {
- id: customTagInput
- width: 150; height: 40
- onAccepted: Loader {
- parent: customTagPage
- tagLabelText = customTagInput.text
- }
- }
- }
I haven’t tested this but I guess it should work. Thanks syrianzoro.
Well one way I can think of this is you can get a handle to the item and reparent it (placing it at the end of the flow?).
If you don’t know what child, but know its screen x,y coordinates, you can use Flow.childAt(x,y).
This topic is similar to what you are asking: http://developer.qt.nokia.com/forums/viewthread/1835/
Basically, store its location and then change it with a state.
You must log in to post a reply. Not a member yet? Register here!


