Button.qml 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import QtQuick 1.0
  2. Rectangle {
  3. id: button
  4. width: 100
  5. height: 50
  6. smooth: true
  7. signal clicked
  8. property alias text: txtButton.text
  9. property alias fontSize: txtButton.font.pixelSize
  10. property alias icon: imgButton.source
  11. radius: 10
  12. gradient: Gradient {
  13. GradientStop { id: gr1; position: 0; color: "white" }
  14. GradientStop { id: gr2; position: 0.5; color: "#ededed" }
  15. GradientStop { id: gr3; position: 1; color: "#d7d7d7" }
  16. }
  17. border.color: "gray"
  18. Image {
  19. id: imgButton
  20. anchors.left: parent.left
  21. anchors.leftMargin: 0.1*button.width
  22. anchors.verticalCenter: parent.verticalCenter
  23. visible: button.icon != "" ? true : false
  24. }
  25. Text {
  26. id: txtButton
  27. anchors.centerIn: parent
  28. font.pixelSize: 28
  29. }
  30. Behavior on scale { NumberAnimation { duration: 80 } }
  31. MouseArea {
  32. id: ma
  33. anchors.fill: parent
  34. onClicked: {
  35. button.clicked()
  36. }
  37. onPressedChanged: {
  38. if( ma.pressed ) {
  39. button.scale = 0.98
  40. gr1.color = "#b7b7b7"
  41. gr2.color = "#b7b7b7"
  42. gr3.color = "#b7b7b7"
  43. } else {
  44. button.scale = 1.0
  45. gr1.color = "white"
  46. gr2.color = "#ededed"
  47. gr3.color = "#d7d7d7"
  48. }
  49. }
  50. }
  51. }