Results 1 to 14 of 14

Thread: Nested lists in QT QML

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

    Default Nested lists in QT QML

    HI,Can I create nested lists using QML ListView in Qt QML?If so how can I do it?
    I tried doing this by making ListView element as a part of the delegate of the another list.
    But only first element of the second list is shown in the view.How can i solve this?

    Thanking You

  2. #2
    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

    You tried correct. But I can assume that you didn't set dimensions of your delegate, eg width and height.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Default Re: Nested lists in QT QML

    Quote Originally Posted by spirit View Post
    You tried correct. But I can assume that you didn't set dimensions of your delegate, eg width and height.
    Hi, here is my qml code...please help me...

    Component{
    id:slidesdelegate

    Item {
    id: sdelegate
    height: scolumn.height +10
    width: sdelegate.ListView.view.width

    Column{
    id:scolumn
    width: parent.width-40;

    Text {
    id: description
    text: model.title
    }

    Rectangle {
    id:viewimages
    height: 20
    width: 70
    color: "#000000"

    Text {
    id: backtext
    text: "View Images"
    color: "#ffffff"
    }

    MouseArea {
    id:view
    anchors.fill: parent
    onClicked: {
    slidesView.viewImagesClicked(index);
    }
    }

    }

    ListView {
    id: insidelist
    model: insidemodel
    delegate: Text {
    id: insidetext
    text: name
    }
    }
    }

    Rectangle {
    width: parent.width; height: 2; color: "#000000"
    anchors.bottom: slidesdelegate.bottom
    }
    }
    }

  4. #4
    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

    I don't see that you set you delegate for a ListView. It should look like:
    Qt Code:
    1. ...
    2. ListView {
    3. id: insidelist
    4. model: insidemodel
    5. delegate: slidesdelegate
    6. }
    7. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Default Re: Nested lists in QT QML

    Hey...if i do like that the application is crashing and i am getting an error like
    'QDeclarativeComponent: Cannot create new component instance before completing the previous'
    i.e., can we set its delegate as 'slidesdelegate'?because 'insidelist' is a member of 'slidesdelegate' right?

  6. #6
    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

    Make a simple test app and try your approach, if it doesn't work, post your test app here.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Default Re: Nested lists in QT QML

    Sorry for the late reply...i tried that in a simple app...but its giving same error..here is my qml code...

    import QtQuick 1.0

    Rectangle {
    width: 360
    height: 360

    ListModel {
    id:model1

    ListElement {
    name: "name"
    }
    ListElement {
    name: "name"
    }
    ListElement {
    name: "name"
    }
    }
    ListModel {
    id:model2
    ListElement {
    name: "inside"
    }
    ListElement {
    name: "inside"
    }
    ListElement {
    name: "inside"
    }
    }
    ListView {
    iduter
    model: model1
    delegate: listdelegate
    }

    Component {
    id:listdelegate

    Item {
    height: col.height

    Column {
    id:col
    Text {
    id:t1
    text: name
    }
    Text {
    id: t2
    text: name
    }
    ListView {
    id:insidelist
    anchors.fill: parent
    model: model2
    delegate: listdelegate
    }
    }
    }
    }
    }

  8. #8
    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

    That's the problem in "insidelist"
    delegate: listdelegate
    It's simple stack-overflow issue.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Default Re: Nested lists in QT QML

    Yes...thank you.
    but now i am using a differnt delegate for that but the lists are overlapping as shown here...http://imgur.com/81NwD
    and also in the inside list only one item is being shown...

    qml code:

    import QtQuick 1.0

    Rectangle {
    width: 360
    height: 360

    ListModel {
    id:model1

    ListElement {
    name: "name"
    }
    ListElement {
    name: "name"
    }
    ListElement {
    name: "name"
    }
    }
    ListModel {
    id:model2
    ListElement {
    name: "inside"
    }
    ListElement {
    name: "inside"
    }
    ListElement {
    name: "inside"
    }
    }

    Component {
    id:delegate2

    Item {
    height: col2.height;

    Column {
    id:col2

    Text {
    id: name1
    text: name
    }

    }
    }
    }

    ListView {
    iduter
    model: model1
    delegate: listdelegate
    }

    Component {
    id:listdelegate

    Item {
    height: col.height

    Column {
    id:col
    Text {
    id:t1
    text: name
    }
    Text {
    id: t2
    text: name
    }
    ListView {
    id:insidelist
    model: model2
    delegate: delegate2
    }
    }
    }
    }
    }
    Last edited by Raghavendra R M; 7th August 2012 at 19:52.

  10. #10
    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].

  11. #11
    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...

  12. #12
    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].

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

    Default Re: Nested lists in QT QML

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

  14. #14
    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.