UserTableView.qml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import QtQuick 2.13
  2. import QtQuick.Controls 2.13
  3. import Qt.labs.qmlmodels 1.0
  4. Rectangle {
  5. property string table_name:"null"
  6. color:"transparent"
  7. //anchors.fill: parent
  8. function add_item(item)
  9. {
  10. //console.log("add_item name:"+item.name+", value :" + item.value)
  11. tableModel.appendRow({"name":item.name,"value":item.value})
  12. }
  13. Rectangle{
  14. id:header
  15. width: parent.width
  16. height: 30
  17. color: "transparent"
  18. Row{
  19. spacing: 0
  20. Repeater{
  21. model: ["项目","外观检查结果"]
  22. Rectangle{
  23. width: {
  24. var w = 0
  25. switch(index){
  26. case 0: w = 130;break;
  27. case 1: w = 230;break;
  28. }
  29. return w
  30. }
  31. height: header.height
  32. color: "#C9DDF8" //"#666666"
  33. border.width: 1
  34. border.color: "#97C4F5" //"#848484"
  35. Text {
  36. text: modelData
  37. anchors.centerIn: parent
  38. font.pointSize: 12
  39. color: "black"
  40. }
  41. }
  42. }
  43. }
  44. }
  45. TableView{
  46. id:tableView
  47. width: parent.width
  48. anchors.top:header.bottom
  49. anchors.left: parent.left
  50. anchors.right: parent.right
  51. anchors.bottom: parent.bottom
  52. clip: true
  53. boundsBehavior: Flickable.OvershootBounds
  54. /*
  55. ScrollBar.vertical: ScrollBar {
  56. anchors.right:parent.right
  57. anchors.rightMargin: 0
  58. visible: tableModel.rowCount > 5
  59. background: Rectangle{
  60. color:"#666666"
  61. }
  62. onActiveChanged: {
  63. active = true;
  64. }
  65. contentItem: Rectangle
  66. {
  67. implicitWidth : 6
  68. implicitHeight : 30
  69. radius : 3
  70. color : "#848484"
  71. }
  72. }
  73. */
  74. model: TableModel {
  75. id:tableModel
  76. TableModelColumn{display: "name"}
  77. TableModelColumn{display: "value"}
  78. }
  79. delegate:DelegateChooser{
  80. DelegateChoice{
  81. column: 0
  82. delegate: Rectangle{
  83. color: "transparent" //"#666666"
  84. implicitWidth: 130
  85. implicitHeight: 32
  86. border.width: 1
  87. border.color: "#97C4F5" //"#848484"
  88. Text {
  89. text: display
  90. anchors.fill: parent
  91. verticalAlignment: Text.AlignVCenter
  92. leftPadding: 10
  93. font.pixelSize: 14
  94. color: "black"
  95. }
  96. }
  97. }
  98. DelegateChoice{
  99. column: 1
  100. delegate: Rectangle{
  101. color: "transparent" //"#666666"
  102. implicitWidth: 230
  103. implicitHeight: 32
  104. border.width: 1
  105. border.color: "#97C4F5" //"#848484"
  106. UserTristate{
  107. id:utr
  108. state: display
  109. onUsateChanged: {
  110. //console.log("b row:"+row+",utr value :" + utr.value +", result:" + model.display)
  111. if("0" === state)
  112. model.display = "0"
  113. if("1" === state)
  114. model.display = "1"
  115. if("2" === state)
  116. model.display = "2"
  117. // console.log("a row:"+row +", name:"+tableModel.rows[row].name +", display:" + model.display)
  118. var itemJson={}
  119. itemJson.table = table_name
  120. itemJson.name = tableModel.rows[row].name
  121. itemJson.value = model.display
  122. testService.set_item_result(JSON.stringify(itemJson))
  123. }
  124. }
  125. }
  126. }
  127. }
  128. }
  129. /*
  130. Component.onCompleted: {
  131. tableModel.appendRow({"name":"小明","value":"0"})
  132. tableModel.appendRow({"name":"小刚","value":"1"})
  133. tableModel.appendRow({"name":"小李","value":"2"})
  134. tableModel.appendRow({"name":"小王","value":"0"})
  135. tableModel.appendRow({"name":"小张","value":"0"})
  136. tableModel.appendRow({"name":"小林","value":"0"})
  137. }
  138. */
  139. }