UserTristate.qml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import QtQuick 2.12
  2. import QtQuick.Controls 2.12
  3. Item {
  4. id:root
  5. anchors.fill: parent
  6. anchors.margins: 1
  7. property int fontsize:14
  8. property string fontcolor:"black"
  9. //property string text:"0.000"
  10. //property int value:0
  11. //property int value_tmp:0
  12. property string text_state1:"合格"
  13. property string text_state2:"不合格"
  14. property string text_state3:"无此项"
  15. signal usateChanged
  16. state: "0"
  17. states:[
  18. State {
  19. name: "0"
  20. PropertyChanges {target:rb1; checked:true}
  21. PropertyChanges {target:rb2; checked:false}
  22. PropertyChanges {target:rb3; checked:false}
  23. },
  24. State {
  25. name: "1"
  26. PropertyChanges {target:rb1; checked:false}
  27. PropertyChanges {target:rb2; checked:true}
  28. PropertyChanges {target:rb3; checked:false}
  29. },
  30. State {
  31. name: "2"
  32. PropertyChanges {target:rb1; checked:false}
  33. PropertyChanges {target:rb2; checked:false}
  34. PropertyChanges {target:rb3; checked:true}
  35. }
  36. ]
  37. ButtonGroup{
  38. id:group
  39. buttons: row.children
  40. /*
  41. onClicked:{
  42. //console.log("tristate clicked:", button.text)
  43. var old_state = state
  44. if(text_state1 === button.text){
  45. state = "0"
  46. }else if(text_state2 === button.text){
  47. state = "1"
  48. }else if(text_state3 === button.text){
  49. state = "2"
  50. }
  51. if(old_state !== state){
  52. //value = value_tmp
  53. root.usateChanged()
  54. }
  55. }
  56. */
  57. }
  58. Row{
  59. id: row
  60. UserRadioButton{
  61. id:rb1
  62. checked: true
  63. text: text_state1
  64. font.pixelSize: fontsize
  65. onCheckedChanged: {
  66. if("0" !== root.state){
  67. //console.log("rb1 onCheckedChanged, rootstate:" , root.state)
  68. root.state = "0"
  69. root.usateChanged()
  70. }
  71. }
  72. }
  73. UserRadioButton{
  74. id:rb2
  75. checked: false
  76. text: text_state2
  77. font.pixelSize: fontsize
  78. onCheckedChanged: {
  79. if("1" !== root.state){
  80. //console.log("rb2 onCheckedChanged, rootstate:" , root.state)
  81. root.state = "1"
  82. root.usateChanged()
  83. }
  84. }
  85. }
  86. UserRadioButton{
  87. id:rb3
  88. checked: false
  89. text: text_state3
  90. font.pixelSize: fontsize
  91. onCheckedChanged: {
  92. if("2" !== root.state){
  93. //console.log("rb2 onCheckedChanged, rootstate:" , root.state)
  94. root.state = "2"
  95. root.usateChanged()
  96. }
  97. }
  98. }
  99. }
  100. }