MyCheckBox.qml 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import QtQuick 1.0
  2. Row {
  3. id: checkBox
  4. property bool checked: false
  5. property alias text: txtCheckBox.text
  6. property alias font: txtCheckBox.font
  7. function setCheck( checked ) {
  8. checkBox.checked = checked
  9. }
  10. state: checked == true ? "check" : "uncheck"
  11. spacing: 20
  12. states: [
  13. State {
  14. name: "check"
  15. PropertyChanges { target: imgCheckDefault; source: "qrc:/qml/images/bar_ok.png" }
  16. },
  17. State {
  18. name: "uncheck"
  19. PropertyChanges { target: imgCheckDefault; source: "qrc:/qml/images/bar_blank.png" }
  20. }
  21. ]
  22. Image {
  23. id: imgCheckDefault
  24. anchors.verticalCenter: parent.verticalCenter
  25. MouseArea {
  26. anchors.fill: parent
  27. onClicked: {
  28. if( checkBox.state == "check" ) {
  29. checkBox.state = "uncheck"
  30. checked = false
  31. } else {
  32. checkBox.state = "check"
  33. checked = true
  34. }
  35. }
  36. }
  37. }
  38. Text {
  39. id: txtCheckBox
  40. anchors.verticalCenter: parent.verticalCenter
  41. text: ""
  42. font.pixelSize: 28
  43. }
  44. } //checkBoxDefault