FluButton.qml 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Controls.Basic
  4. import FluentUI
  5. Button {
  6. property bool disabled: false
  7. property color normalColor: FluTheme.dark ? Qt.rgba(62/255,62/255,62/255,1) : Qt.rgba(254/255,254/255,254/255,1)
  8. property color hoverColor: FluTheme.dark ? Qt.rgba(68/255,68/255,68/255,1) : Qt.rgba(251/255,251/255,251/255,1)
  9. property color disableColor: FluTheme.dark ? Qt.rgba(59/255,59/255,59/255,1) : Qt.rgba(252/255,252/255,252/255,1)
  10. id: control
  11. topPadding:5
  12. bottomPadding:5
  13. leftPadding:15
  14. rightPadding:15
  15. enabled: !disabled
  16. focusPolicy:Qt.TabFocus
  17. Keys.onSpacePressed: control.visualFocus&&clicked()
  18. background: Rectangle{
  19. border.color: FluTheme.dark ? "#505050" : "#DFDFDF"
  20. border.width: 1
  21. radius: 4
  22. FluFocusRectangle{
  23. visible: control.visualFocus
  24. radius:8
  25. }
  26. color:{
  27. if(disabled){
  28. return disableColor
  29. }
  30. return hovered ? hoverColor :normalColor
  31. }
  32. }
  33. contentItem: FluText {
  34. text: control.text
  35. horizontalAlignment: Text.AlignHCenter
  36. verticalAlignment: Text.AlignVCenter
  37. color: {
  38. if(FluTheme.dark){
  39. if(disabled){
  40. return Qt.rgba(131/255,131/255,131/255,1)
  41. }
  42. if(pressed){
  43. return Qt.rgba(162/255,162/255,162/255,1)
  44. }
  45. return Qt.rgba(1,1,1,1)
  46. }else{
  47. if(disabled){
  48. return Qt.rgba(160/255,160/255,160/255,1)
  49. }
  50. if(pressed){
  51. return Qt.rgba(96/255,96/255,96/255,1)
  52. }
  53. return Qt.rgba(0,0,0,1)
  54. }
  55. }
  56. }
  57. }