Results 1 to 14 of 14

Thread: Nested lists in QT QML

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Nested lists in QT QML

    here we go
    Qt Code:
    1. import QtQuick 1.0
    2.  
    3. Rectangle {
    4. width: 360
    5. height: 360
    6.  
    7. ListModel {
    8. id: model1
    9.  
    10. ListElement {
    11. name: "name"
    12. }
    13. ListElement {
    14. name: "name"
    15. }
    16. ListElement {
    17. name: "name"
    18. }
    19. }
    20. ListModel {
    21. id: model2
    22. ListElement {
    23. name: "inside"
    24. }
    25. ListElement {
    26. name: "inside"
    27. }
    28. ListElement {
    29. name: "inside"
    30. }
    31. }
    32.  
    33. Component {
    34. id: delegate2
    35.  
    36. Item {
    37. width: 100
    38. height: col.childrenRect.height
    39.  
    40. Column {
    41. id: col2
    42.  
    43. Text {
    44. id: name1
    45. text: name
    46. anchors.left: parent.left
    47. anchors.right: parent.right
    48. }
    49. }
    50. }
    51. }
    52.  
    53. ListView {
    54. id: outer
    55. model: model1
    56. delegate: listdelegate
    57. }
    58.  
    59. Component {
    60. id: listdelegate
    61.  
    62. Item {
    63. width: 100
    64. height: col.childrenRect.height
    65.  
    66. Column {
    67. id: col
    68. Text {
    69. id: t1
    70. text: name
    71. anchors.left: parent.left
    72. anchors.right: parent.right
    73. }
    74. Text {
    75. id: t2
    76. text: name
    77. anchors.left: parent.left
    78. anchors.right: parent.right
    79. }
    80. ListView {
    81. id: insidelist
    82. model: model2
    83. delegate: delegate2
    84. height: contentItem.height
    85. anchors.left: parent.left
    86. anchors.right: parent.right
    87. }
    88. }
    89. }
    90. }
    91. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  2. #2
    Join Date
    Aug 2012
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Nested lists in QT QML

    Hi ! now the overlapping problem is solved...thank you
    But again the nested lists are not working right?
    i mean the output should have been 'inside' repeated 3 times under each 'name' right?
    I'm sorry if i am disturbing you...but i am helpless...

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Nested lists in QT QML

    Qt Code:
    1. import QtQuick 1.0
    2.  
    3. Rectangle {
    4. width: 360
    5. height: 360
    6.  
    7. ListModel {
    8. id: model1
    9.  
    10. ListElement {
    11. name: "name"
    12. }
    13. ListElement {
    14. name: "name"
    15. }
    16. ListElement {
    17. name: "name"
    18. }
    19. }
    20. ListModel {
    21. id: model2
    22. ListElement {
    23. name: "inside"
    24. }
    25. ListElement {
    26. name: "inside"
    27. }
    28. ListElement {
    29. name: "inside"
    30. }
    31. }
    32.  
    33. Component {
    34. id: delegate2
    35.  
    36. Item {
    37. width: 100
    38. height: col2.childrenRect.height
    39.  
    40. Column {
    41. id: col2
    42. anchors.left: parent.left
    43. anchors.right: parent.right
    44. Text {
    45. id: name1
    46. text: name
    47. }
    48. }
    49. }
    50. }
    51.  
    52. ListView {
    53. id: outer
    54. model: model1
    55. delegate: listdelegate
    56. anchors.fill: parent
    57. }
    58.  
    59. Component {
    60. id: listdelegate
    61.  
    62. Item {
    63. width: 100
    64. height: col.childrenRect.height
    65.  
    66. Column {
    67. id: col
    68. anchors.left: parent.left
    69. anchors.right: parent.right
    70. Text {
    71. id: t1
    72. text: name
    73. }
    74. Text {
    75. id: t2
    76. text: name
    77. }
    78. ListView {
    79. id: insidelist
    80. model: model2
    81. delegate: delegate2
    82. contentHeight: contentItem.childrenRect.height
    83. height: childrenRect.height
    84. anchors.left: parent.left
    85. anchors.right: parent.right
    86. clip: true
    87. }
    88. }
    89. }
    90. }
    91. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  4. #4
    Join Date
    Aug 2012
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Nested lists in QT QML

    Its solved...!! Thanks a lot...:-) :-) :-)

  5. #5
    Join Date
    Oct 2013
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Nested lists in QT QML

    Hi

    Attempting to fix my similar issue from this older thread.

    In the case referenced by the example code above - what should be altered if the inside models where to be unique for each entry in the outside list? Eg produce this output;:

    model1:1
    model2:1
    model2:2
    model2:3
    model1:2
    model3:1
    model3:2
    model3:3



    Thanks!

    Mikkel
    Last edited by mhaugstrup; 14th October 2013 at 10:31.

Similar Threads

  1. nested lists in QTextDocumentFragment::toHtml()
    By Al_ in forum Qt Programming
    Replies: 0
    Last Post: 2nd March 2012, 09:16
  2. Inputting Into Lists
    By kiyoutee in forum Newbie
    Replies: 2
    Last Post: 2nd March 2011, 07:48
  3. Hi all, some about lists and views
    By kosasker in forum Newbie
    Replies: 4
    Last Post: 24th January 2011, 12:55
  4. display lists
    By rick_st3 in forum Newbie
    Replies: 3
    Last Post: 22nd June 2008, 23:09
  5. Some problems with lists
    By gdiepen in forum Qt Programming
    Replies: 9
    Last Post: 16th January 2008, 16:54

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.