import QtQuick 2.13 import QtQuick.Controls 2.13 import Qt.labs.qmlmodels 1.0 Rectangle { property string table_name:"null" color:"transparent" //anchors.fill: parent function add_item(item) { //console.log("add_item name:"+item.name+", value :" + item.value) tableModel.appendRow({"name":item.name,"value":item.value}) } Rectangle{ id:header width: parent.width height: 30 color: "transparent" Row{ spacing: 0 Repeater{ model: ["项目","外观检查结果"] Rectangle{ width: { var w = 0 switch(index){ case 0: w = 130;break; case 1: w = 230;break; } return w } height: header.height color: "#C9DDF8" //"#666666" border.width: 1 border.color: "#97C4F5" //"#848484" Text { text: modelData anchors.centerIn: parent font.pointSize: 12 color: "black" } } } } } TableView{ id:tableView width: parent.width anchors.top:header.bottom anchors.left: parent.left anchors.right: parent.right anchors.bottom: parent.bottom clip: true boundsBehavior: Flickable.OvershootBounds /* ScrollBar.vertical: ScrollBar { anchors.right:parent.right anchors.rightMargin: 0 visible: tableModel.rowCount > 5 background: Rectangle{ color:"#666666" } onActiveChanged: { active = true; } contentItem: Rectangle { implicitWidth : 6 implicitHeight : 30 radius : 3 color : "#848484" } } */ model: TableModel { id:tableModel TableModelColumn{display: "name"} TableModelColumn{display: "value"} } delegate:DelegateChooser{ DelegateChoice{ column: 0 delegate: Rectangle{ color: "transparent" //"#666666" implicitWidth: 130 implicitHeight: 32 border.width: 1 border.color: "#97C4F5" //"#848484" Text { text: display anchors.fill: parent verticalAlignment: Text.AlignVCenter leftPadding: 10 font.pixelSize: 14 color: "black" } } } DelegateChoice{ column: 1 delegate: Rectangle{ color: "transparent" //"#666666" implicitWidth: 230 implicitHeight: 32 border.width: 1 border.color: "#97C4F5" //"#848484" UserTristate{ id:utr state: display onUsateChanged: { //console.log("b row:"+row+",utr value :" + utr.value +", result:" + model.display) if("0" === state) model.display = "0" if("1" === state) model.display = "1" if("2" === state) model.display = "2" // console.log("a row:"+row +", name:"+tableModel.rows[row].name +", display:" + model.display) var itemJson={} itemJson.table = table_name itemJson.name = tableModel.rows[row].name itemJson.value = model.display testService.set_item_result(JSON.stringify(itemJson)) } } } } } } /* Component.onCompleted: { tableModel.appendRow({"name":"小明","value":"0"}) tableModel.appendRow({"name":"小刚","value":"1"}) tableModel.appendRow({"name":"小李","value":"2"}) tableModel.appendRow({"name":"小王","value":"0"}) tableModel.appendRow({"name":"小张","value":"0"}) tableModel.appendRow({"name":"小林","value":"0"}) } */ }