Results 1 to 2 of 2

Thread: Displaying a data structure with children in a view

  1. #1
    Join Date
    Sep 2011
    Posts
    20
    Qt products
    Qt5
    Platforms
    Windows

    Default Displaying a data structure with children in a view

    I have a data structure like this:

    Qt Code:
    1. struct List {
    2. int32_t id {-1};
    3. int32_t seen {0};
    4. int32_t total {0};
    5. int32_t lastModified {-1};
    6. bool isFavorite {false};
    7. bool isWatchlist {false};
    8. bool isDislike {false};
    9. QString name {};
    10. QList<List> children {};
    11. }
    To copy to clipboard, switch view to plain text mode 

    I load the data in a model derived from QAbstractListModel which is attached to a default QListView and a custom delegate then renders the List objects like this:



    These lists can also have children. And those children can have other children. And each "level" should have some indentation compared to its parent. I'd like to render each list with the above delegate. What would be the easiest way to do this? I can change the data structure if needed.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Displaying a data structure with children in a view

    That sounds like you want a tree model and a tree view.

    Cheers,
    _

Similar Threads

  1. Replies: 4
    Last Post: 22nd January 2013, 19:53
  2. model/view json data displaying
    By binaural in forum Qt Programming
    Replies: 5
    Last Post: 27th June 2012, 08:13
  3. Replies: 1
    Last Post: 3rd October 2011, 15:40
  4. Data structure reference in Model/View Framework
    By jimc1200 in forum Qt Programming
    Replies: 4
    Last Post: 14th September 2009, 20:23
  5. Replies: 1
    Last Post: 1st March 2006, 11:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.