UserTristate.qml 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. onClicked:{
  41. //console.log("tristate clicked:", button.text)
  42. var old_state = state
  43. if(text_state1 === button.text){
  44. state = "0"
  45. }else if(text_state2 === button.text){
  46. state = "1"
  47. }else if(text_state3 === button.text){
  48. state = "2"
  49. }
  50. if(old_state !== state){
  51. //value = value_tmp
  52. root.usateChanged()
  53. }
  54. }
  55. }
  56. Row{
  57. id: row
  58. UserRadioButton{
  59. id:rb1
  60. checked: true
  61. text: text_state1
  62. font.pixelSize: fontsize
  63. }
  64. UserRadioButton{
  65. id:rb2
  66. checked: false
  67. text: text_state2
  68. font.pixelSize: fontsize
  69. }
  70. UserRadioButton{
  71. id:rb3
  72. checked: false
  73. text: text_state3
  74. font.pixelSize: fontsize
  75. }
  76. }
  77. }