Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.6KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Pixmap Button, a custom Qt4 widget
  4. # Copyright (C) 2013 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation; either version 2 of
  9. # the License, or any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # For a full copy of the GNU General Public License see the doc/GPL.txt file.
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Global)
  19. from PyQt5.QtCore import QRectF
  20. from PyQt5.QtGui import QPainter, QPixmap
  21. from PyQt5.QtWidgets import QPushButton
  22. # ------------------------------------------------------------------------------------------------------------
  23. # Widget Class
  24. class PixmapButton(QPushButton):
  25. def __init__(self, parent):
  26. QPushButton.__init__(self, parent)
  27. self.fPixmapNormal = QPixmap()
  28. self.fPixmapDown = QPixmap()
  29. self.fPixmapHover = QPixmap()
  30. self.fPixmapRect = QRectF(0, 0, 0, 0)
  31. self.fIsHovered = False
  32. self.setText("")
  33. def setPixmaps(self, normal, down, hover):
  34. self.fPixmapNormal.load(normal)
  35. self.fPixmapDown.load(down)
  36. self.fPixmapHover.load(hover)
  37. width = self.fPixmapNormal.width()
  38. height = self.fPixmapNormal.height()
  39. self.fPixmapRect = QRectF(0, 0, width, height)
  40. self.setMinimumSize(width, height)
  41. self.setMaximumSize(width, height)
  42. def enterEvent(self, event):
  43. self.fIsHovered = True
  44. QPushButton.enterEvent(self, event)
  45. def leaveEvent(self, event):
  46. self.fIsHovered = False
  47. QPushButton.leaveEvent(self, event)
  48. def paintEvent(self, event):
  49. painter = QPainter(self)
  50. event.accept()
  51. if not self.isEnabled():
  52. painter.save()
  53. painter.setOpacity(0.2)
  54. painter.drawPixmap(self.fPixmapRect, self.fPixmapNormal, self.fPixmapRect)
  55. painter.restore()
  56. elif self.isChecked() or self.isDown():
  57. painter.drawPixmap(self.fPixmapRect, self.fPixmapDown, self.fPixmapRect)
  58. elif self.fIsHovered:
  59. painter.drawPixmap(self.fPixmapRect, self.fPixmapHover, self.fPixmapRect)
  60. else:
  61. painter.drawPixmap(self.fPixmapRect, self.fPixmapNormal, self.fPixmapRect)