Results 1 to 7 of 7

Thread: Selection of Child Checkbox using Header Checkbox and viceversa

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Jul 2013
    Posts
    33
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Selection of Child Checkbox using Header Checkbox and viceversa

    Hi
    I have done that...
    onCheckedChanged() //on delegate checkbix
    {
    //here i am changing the header checkbox state. The moment i change header checkbox again its oncheckedChanged is emitted.so all the properties of list is set accordingly
    }


    Regards
    Bala B


    Added after 7 minutes:


    Hi
    Here i post my entire new code which i could get the requirement done with some issues (not sure is it binding issue)

    Here in this code i was able to select/unselect using header and when any child element gets changed header gets deselected.When all the child elements are selected header gets selected.But the issue here is once child elements gets changed its state ,header is not able to set the state back,but when you click on header it successfully updates the child elements list model.I verified the values.But the checkbox front end is not getting selected/unselected..

    Qt Code:
    1. Rectangle{
    2. id: header
    3. width: 620
    4. height: 70
    5. y: 150
    6. color: "#E8E8E8"
    7. anchors{left: parent.left;leftMargin: 110;top:separator.bottom}
    8.  
    9. CheckBox {
    10. id: headerCombo
    11. text: qsTr("Select All")
    12. checked: false
    13. anchors{left: parent.left;leftMargin: 38;top:parent.top;topMargin: 20}
    14. onCheckedChanged: {
    15.  
    16. if(headerCombo.pressed)
    17. {
    18. console.log("checjed chaneging")
    19. for(var i=0;i<checkBoxModel.count;i++)
    20. {
    21. checkBoxModel.set(i,{"selected": headerCombo.checked})
    22. }
    23. }
    24. }
    25. }
    26. }
    27. ListModel {
    28. id: checkBoxModel
    29. ListElement { selected: false; }
    30. ListElement { selected: false; }
    31. ListElement { selected: false; }
    32. ListElement { selected: false; }
    33. ListElement { selected: false; }
    34. ListElement { selected: false; }
    35. }
    36.  
    37.  
    38. ListView{
    39. id: listt
    40. model: checkBoxModel
    41. clip:true
    42. width: 620
    43. anchors{left: parent.left;leftMargin: 110;top: header.bottom;topMargin: 10;bottom: bottomBar.top}
    44. delegate: listDelegate
    45. }
    46.  
    47. Component {
    48. id: listDelegate
    49.  
    50. Warnings{ //consider this item as checkbox
    51. id: warningsList
    52. width: 620
    53. color: "#EFF0F0"
    54. childChkBox: selected //this is checked property
    55. onChildChanged: {
    56.  
    57. if(!headerCombo.pressed && childChkBox===true){
    58. console.log(" changed by child true")
    59. checkBoxModel.set(index,{"selected": true})
    60. checkSelection()
    61. }
    62. else if(!headerCombo.pressed && childChkBox===false){
    63. console.log(" changed by child false")
    64. checkBoxModel.set(index,{"selected": false})
    65. checkSelection()
    66. }
    67. else
    68. {
    69. console.log(" changed by Parent")
    70. for(var i=0;i<checkBoxModel.count;i++)
    71. {
    72. checkBoxModel.set(index,{"selected": headerCombo.checked})
    73. }
    74. }
    75.  
    76. // function checkSelection1()
    77. // {
    78.  
    79. // for(var i=0;i<checkBoxModel.count;i++)
    80. // {
    81. // if(checkBoxModel.get(i).selected===true){
    82. // headerValue=true
    83. // }
    84. // else
    85. // headerValue=false
    86.  
    87. // }
    88.  
    89.  
    90. // }
    91.  
    92.  
    93.  
    94. function checkSelection()
    95. {
    96. if(checkBoxModel.get(0).selected===true)
    97. {
    98. if(checkBoxModel.get(1).selected===true)
    99. {
    100. if(checkBoxModel.get(2).selected===true)
    101. {
    102. if(checkBoxModel.get(3).selected===true)
    103. {
    104. if(checkBoxModel.get(4).selected===true)
    105. {
    106. if(checkBoxModel.get(5).selected===true)
    107. {
    108. headerValue=true
    109. }
    110. else
    111. {
    112. headerValue=false
    113. }
    114. }
    115. else
    116. {
    117. headerValue=false
    118. }
    119. }
    120. else
    121. {
    122. headerValue=false
    123. }
    124. }
    125. else
    126. {
    127. headerValue=false
    128. }
    129. }
    130. else
    131. {
    132. headerValue=false
    133. }
    134. }
    135. else
    136. {
    137. headerValue=false
    138. }
    139. }
    140. }
    141. }
    142. }
    To copy to clipboard, switch view to plain text mode 


    Thanks in Advance


    Regards
    Bala B
    Last edited by beemaneni; 26th October 2015 at 09:50.

Similar Threads

  1. Replies: 5
    Last Post: 30th September 2013, 23:03
  2. Replies: 0
    Last Post: 12th January 2012, 06:41
  3. Replies: 4
    Last Post: 1st June 2011, 14:54
  4. checkbox
    By nErnie in forum Qt Programming
    Replies: 1
    Last Post: 25th September 2006, 21:59
  5. CheckBox and selection in QTableView
    By Mike Krus in forum Qt Programming
    Replies: 1
    Last Post: 21st September 2006, 20:31

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.