Results 1 to 2 of 2

Thread: ListView _ TreeView

  1. #1
    Join Date
    Jan 2016
    Posts
    54
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default ListView _ TreeView

    Hello Forum

    I want to transform a static structure to a dynamic :

    Example:
    Qt Code:
    1. ListModel {
    2. ListElement {
    3. categoryName: "ABC"
    4. subItems: [
    5. ListElement { itemName: "aaa"},
    6. ListElement { itemName: "bbb"}
    7. ]
    8. }
    9. ListElement {
    10. categoryName: "ABC"
    11. subItems: [
    12. ListElement { itemName: "aaa"},
    13. ListElement { itemName: "bbb"}
    14. ]
    15. }
    16. ListElement {
    17. categoryName: "ABC"
    18. subItems: [
    19. ListElement { itemName: "aaa"},
    20. ListElement { itemName: "bbb"}
    21. ]
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    Dynamic :
    Qt Code:
    1. ListModel {
    2. Component.onCompleted: {
    3. for(var i = 0; i < 2; ++i) {
    4. append({
    5. "categoryName": "ABC",
    6. "subItems": [
    7. {"itemName": "aaa"},
    8. {"itemName": "bbb"}
    9. ]
    10. })
    11. }
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    Until here everything is good


    My Question: How can I transform the below static structure to dynamic

    Qt Code:
    1. ListModel {
    2. ListElement {
    3. categoryName: "ABC"
    4. subItems: [
    5. ListElement { itemName: "aaa"},
    6. ListElement { itemName: "bbb"}
    7. ]
    8. }
    9. ListElement {
    10. categoryName: "DEF"
    11. subItems: [
    12. ListElement { itemName: "ccc"},
    13. ListElement { itemName: "ddd"}
    14. ]
    15. }
    16. ListElement {
    17. categoryName: "GHI"
    18. subItems: [
    19. ListElement { itemName: "eee"},
    20. ListElement { itemName: "fff"},
    21. ListElement { itemName: "ggg"}
    22. ]
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 

    The problem is I don't know the size of SubItems !!

    First : I get the projects (list of project)
    Second : I get for each project list of files (list of files)

    I want to present this structure :
    project0
    file1
    file2
    project1
    file3
    file4
    project2
    file5
    file6
    file7

    I try this, not work well !
    Qt Code:
    1. ListModel {
    2. id: menuModel
    3. Component.onCompleted: {
    4.  
    5. var listProjects = handledProjets()
    6. for(var k=0; k<listProjects.length; k++)
    7. {
    8. var nameplugin = listProjects[k]
    9. console.log(">>> Projet = "+nameplugin)
    10. //menuModel.append({text:nameplugin})
    11. //append({"categoryName": nameplugin})
    12.  
    13. var listFiles = handledFiles(nameplugin)
    14. console.log(">>> File("+(l+1)+") = "+listFiles[l])
    15. //mychild.append({text:listFiles[l]})
    16. append({
    17. "categoryName": nameplugin
    18. "subItems": [
    19. {"itemName": listFiles[l]}
    20. ]
    21. })
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    Cheers;

  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: ListView _ TreeView

    This sounds like a use case for a proper custom model, i.e. a custom implementation derived from QAbstractListModel or even QAbstractItemModel.

    How do you display this?

    Cheers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 16th May 2016, 23:50
  2. ListView - ListView communication
    By MarkoSan in forum Qt Quick
    Replies: 1
    Last Post: 30th October 2015, 10:18
  3. Hierarchical TreeView
    By cia.michele in forum Qt-based Software
    Replies: 0
    Last Post: 18th April 2011, 08:08
  4. CheckBox in treeview
    By ansar in forum Qt Programming
    Replies: 2
    Last Post: 16th December 2009, 05:41
  5. Proxy for TreeView
    By patrikd in forum Qt Programming
    Replies: 5
    Last Post: 8th February 2008, 19:12

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.