UserTristate.qml 3.1 KB

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