Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Creating dynamic objects separately in delegates of a listview
Forum Updated to NodeBB v4.3 + New Features

Creating dynamic objects separately in delegates of a listview

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlqt5
3 Posts 2 Posters 370 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • jjgccgJ Offline
    jjgccgJ Offline
    jjgccg
    wrote on last edited by jjgccg
    #1

    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:

    mpckup.PNG

    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.

    GrecKoG 1 Reply Last reply
    0
    • jjgccgJ jjgccg

      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:

      mpckup.PNG

      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.

      GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      @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.

      jjgccgJ 1 Reply Last reply
      0
      • GrecKoG GrecKo

        @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.

        jjgccgJ Offline
        jjgccgJ Offline
        jjgccg
        wrote on last edited by jjgccg
        #3
        This post is deleted!
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved