import QtQuick 2.12 import QtQuick.Controls 2.12 Item { id:root anchors.fill: parent anchors.margins: 1 property int fontsize:14 property string fontcolor:"black" //property string text:"0.000" //property int value:0 //property int value_tmp:0 property string text_state1:"合格" property string text_state2:"不合格" property string text_state3:"无此项" signal usateChanged state: "0" states:[ State { name: "0" PropertyChanges {target:rb1; checked:true} PropertyChanges {target:rb2; checked:false} PropertyChanges {target:rb3; checked:false} }, State { name: "1" PropertyChanges {target:rb1; checked:false} PropertyChanges {target:rb2; checked:true} PropertyChanges {target:rb3; checked:false} }, State { name: "2" PropertyChanges {target:rb1; checked:false} PropertyChanges {target:rb2; checked:false} PropertyChanges {target:rb3; checked:true} } ] ButtonGroup{ id:group buttons: row.children onClicked:{ //console.log("tristate clicked:", button.text) var old_state = state if(text_state1 === button.text){ state = "0" }else if(text_state2 === button.text){ state = "1" }else if(text_state3 === button.text){ state = "2" } if(old_state !== state){ //value = value_tmp root.usateChanged() } } } Row{ id: row UserRadioButton{ id:rb1 checked: true text: text_state1 font.pixelSize: fontsize } UserRadioButton{ id:rb2 checked: false text: text_state2 font.pixelSize: fontsize } UserRadioButton{ id:rb3 checked: false text: text_state3 font.pixelSize: fontsize } } }