Creating dynamic objects separately in delegates of a listview
-
I have something like a timeline on a horizontal axis. On the vertical axis is a ListView, and each listview has a customizable number of "time slot" objects that display data as a rectangle whose width is based on the start and end times of the time slot. The user can dynamically add and remove time slots. Here is a mockup of what I'm trying to create:
I've been able to display these for a single delegate in my list view using dynamic object creation using a mapping of seconds to pixels to adjust the x-value. The problem is, each delegate, although different instances, contain objects which have identical ID's.
So inside of a delegate file, whenever I try to dynamically add and remove rectangles by adding them to a component ID, it propagates through the rest of the code and adds or removes the rectangles to all of the other delegate components instead of the single delegate instance. The result is that, in the mockup above, adding the 4 time slot rectangles to the second Target would also add them to the first Target.
Instead of dynamic object creation, here are some alternatives I have tried that have failed:
- Repeater - The backend C++ QAbstractListModel changes dynamically based off of the addition/removal of rectangle time slots as the user modifies the timeline, so this will not work, as it renders the rectangles once at the beginning of the application and does not change.
- Horizontal ListView - The behavior of the ListView is what I really need (modifying the backend model automatically updates front end components). However, it does not work in this case because the rectangles need to have every variation of spacing, and ListView seems to only allow for a fixed spacing or no spacing at all.
Do you have any suggestions on QML types I should use to do this? I feel like I've tried everything. Let me know if you need me to provide any code samples. Thanks in advance.
-
I have something like a timeline on a horizontal axis. On the vertical axis is a ListView, and each listview has a customizable number of "time slot" objects that display data as a rectangle whose width is based on the start and end times of the time slot. The user can dynamically add and remove time slots. Here is a mockup of what I'm trying to create:
I've been able to display these for a single delegate in my list view using dynamic object creation using a mapping of seconds to pixels to adjust the x-value. The problem is, each delegate, although different instances, contain objects which have identical ID's.
So inside of a delegate file, whenever I try to dynamically add and remove rectangles by adding them to a component ID, it propagates through the rest of the code and adds or removes the rectangles to all of the other delegate components instead of the single delegate instance. The result is that, in the mockup above, adding the 4 time slot rectangles to the second Target would also add them to the first Target.
Instead of dynamic object creation, here are some alternatives I have tried that have failed:
- Repeater - The backend C++ QAbstractListModel changes dynamically based off of the addition/removal of rectangle time slots as the user modifies the timeline, so this will not work, as it renders the rectangles once at the beginning of the application and does not change.
- Horizontal ListView - The behavior of the ListView is what I really need (modifying the backend model automatically updates front end components). However, it does not work in this case because the rectangles need to have every variation of spacing, and ListView seems to only allow for a fixed spacing or no spacing at all.
Do you have any suggestions on QML types I should use to do this? I feel like I've tried everything. Let me know if you need me to provide any code samples. Thanks in advance.
@jjgccg said in Creating dynamic objects separately in delegates of a listview:
Repeater - The backend C++ QAbstractListModel changes dynamically based off of the addition/removal of rectangle time slots as the user modifies the timeline, so this will not work, as it renders the rectangles once at the beginning of the application and does not change.
Repeater does update its delegates if the model changes, it is the component to use here.
-
@jjgccg said in Creating dynamic objects separately in delegates of a listview:
Repeater - The backend C++ QAbstractListModel changes dynamically based off of the addition/removal of rectangle time slots as the user modifies the timeline, so this will not work, as it renders the rectangles once at the beginning of the application and does not change.
Repeater does update its delegates if the model changes, it is the component to use here.