Results 1 to 12 of 12

Thread: interaction StackView / ListView

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Dec 2015
    Posts
    35
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Wink Re: interaction StackView / ListView

    Thanks,

    I have 2 delegates:
    1 for main menu
    2 for subMenu

    here is my code:
    Qt Code:
    1. ListView {
    2. width: 250
    3. height: root.height
    4. anchors.right: parent.right
    5.  
    6. model: menuModel
    7. delegate: categoryDelegate
    8. boundsBehavior: Flickable.StopAtBounds
    9. }
    10.  
    11. ListModel {
    12. id: menuModel
    13. ListElement {
    14. categoryName: "Acceuil"
    15. collapsed: true
    16.  
    17. // A ListElement can't contain child elements, but it can contain
    18. // a list of elements. A list of ListElements can be used as a model
    19. // just like any other model type.
    20. subItems: [
    21. ListElement { itemName: "1" },
    22. ListElement { itemName: "2" },
    23. ListElement { itemName: "3" },
    24. ListElement { itemName: "4" }
    25. ]
    26. }
    27.  
    28. ListElement {
    29. categoryName: "Compte"
    30. collapsed: true
    31. subItems: [
    32. ListElement { itemName: "1" },
    33. ListElement { itemName: "2" }
    34. ]
    35. }
    36.  
    37. ListElement {
    38. categoryName: "Outils"
    39. collapsed: true
    40. subItems: [
    41. ListElement { itemName: "1" },
    42. ListElement { itemName: "2" },
    43. ListElement { itemName: "3" }
    44. ]
    45. }
    46.  
    47. ListElement {
    48. categoryName: "Statistiques"
    49. collapsed: true
    50. subItems: [
    51. ListElement { itemName: "Naissances" },
    52. ListElement { itemName: "Deces" }
    53. ]
    54. }
    55. ListElement {
    56. categoryName: "Parametres"
    57. collapsed: true
    58. subItems: [
    59. ListElement { itemName: "1" },
    60. ListElement { itemName: "2" }
    61. ]
    62. }
    63. }
    64.  
    65. Component {
    66. id: categoryDelegate
    67. Column {
    68. Rectangle {
    69. id: categoryItem
    70. color: base
    71. border.color: Qt.lighter(color, 1.5)
    72. height: 50
    73. width: 250
    74. Text {
    75. anchors.centerIn: parent
    76. color: "#f2f2f2"
    77. font.pixelSize: 25
    78. text: categoryName
    79. font.family: "MS Reference Sans Serif"
    80. }
    81. Image {
    82. id: fleche
    83. source: "img/fleche.png"
    84. sourceSize.width: 25
    85. sourceSize.height: 25
    86. anchors.left: parent.left
    87. anchors.leftMargin: 6
    88. anchors.verticalCenter: parent.verticalCenter
    89. }
    90. MouseArea {
    91. anchors.fill: parent
    92. hoverEnabled: true
    93.  
    94. // Toggle the 'collapsed' property
    95. onClicked: {
    96. console.log(menuModel.get(1).categoryName)
    97. fleche.rotation+=180
    98. menuModel.setProperty(index, "collapsed", !collapsed)
    99. }
    100. onEntered: categoryItem.color = "#0d0d0d"
    101. onExited: categoryItem.color = base
    102. }
    103. }
    104. Loader {
    105. id: subItemLoader
    106.  
    107. // This is a workaround for a bug/feature in the Loader element. If sourceComponent is set to null
    108. // the Loader element retains the same height it had when sourceComponent was set. Setting visible
    109. // to false makes the parent Column treat it as if it's height was 0.
    110. visible: !collapsed
    111. property variant subItemModel : subItems
    112. sourceComponent: collapsed ? null : subItemColumnDelegate
    113. onStatusChanged: if (status == Loader.Ready) item.model = subItemModel
    114. }
    115. }
    116. }
    117. Component {
    118. id: subItemColumnDelegate
    119. Column {
    120. property alias model : subItemRepeater.model
    121. Repeater {
    122. id: subItemRepeater
    123. delegate: Rectangle {
    124. id: rectangle1
    125.  
    126. height: 40
    127. width: 250
    128. color: "#8c8c8c"
    129. border.color: Qt.lighter(color)
    130. //border.width: 2
    131.  
    132. Text {
    133. id: subItemText
    134. //anchors.centerIn: parent
    135. font.pixelSize: 16
    136. text: itemName
    137. anchors.left: parent.left
    138. anchors.leftMargin: 20
    139. anchors.verticalCenter: parent.verticalCenter
    140. }
    141. MouseArea {
    142. anchors.fill: parent
    143. hoverEnabled: true
    144.  
    145. // Toggle the 'collapsed' property
    146. onClicked:{
    147. console.log(menuModel.get(0).categoryName)
    148. stack.push(view2)}
    149.  
    150. onEntered: {
    151. rectangle1.color= "#999999"
    152. subItemText.color = "white"
    153. }
    154. onExited: {
    155. rectangle1.color= "#8c8c8c"
    156. subItemText.color = "black"
    157. }
    158. }
    159. }
    160. }
    161. }
    162. }
    163. StackView{
    To copy to clipboard, switch view to plain text mode 

    Can you add the modifications in the code above to solve the problem

    Cheers,
    Last edited by RegMe; 14th January 2016 at 10:50.

Similar Threads

  1. ListView - ListView communication
    By MarkoSan in forum Qt Quick
    Replies: 1
    Last Post: 30th October 2015, 10:18
  2. StackView get index or views page
    By KeineAhnung in forum Newbie
    Replies: 2
    Last Post: 18th November 2014, 22:03
  3. Any example of StackView?
    By stereoMatching in forum Qt Quick
    Replies: 1
    Last Post: 16th December 2013, 08:07
  4. QML and C++ interaction
    By cueMan in forum Qt Programming
    Replies: 3
    Last Post: 11th November 2010, 07:30
  5. Qt interaction with X11
    By qwakaw in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2008, 20:17

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.