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.

pixmapbutton.py 2.7KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. try:
  20. from PyQt5.QtCore import QRectF
  21. from PyQt5.QtGui import QPainter, QPixmap
  22. from PyQt5.QtWidgets import QPushButton
  23. except:
  24. from PyQt4.QtCore import QRectF
  25. from PyQt4.QtGui import QPainter, QPixmap, QPushButton
  26. # ------------------------------------------------------------------------------------------------------------
  27. # Widget Class
  28. class PixmapButton(QPushButton):
  29. def __init__(self, parent):
  30. QPushButton.__init__(self, parent)
  31. self.fPixmapNormal = QPixmap()
  32. self.fPixmapDown = QPixmap()
  33. self.fPixmapHover = QPixmap()
  34. self.fPixmapRect = QRectF(0, 0, 0, 0)
  35. self.fIsHovered = False
  36. self.setText("")
  37. def setPixmaps(self, normal, down, hover):
  38. self.fPixmapNormal.load(normal)
  39. self.fPixmapDown.load(down)
  40. self.fPixmapHover.load(hover)
  41. width = self.fPixmapNormal.width()
  42. height = self.fPixmapNormal.height()
  43. self.fPixmapRect = QRectF(0, 0, width, height)
  44. self.setMinimumSize(width, height)
  45. self.setMaximumSize(width, height)
  46. def enterEvent(self, event):
  47. self.fIsHovered = True
  48. QPushButton.enterEvent(self, event)
  49. def leaveEvent(self, event):
  50. self.fIsHovered = False
  51. QPushButton.leaveEvent(self, event)
  52. def paintEvent(self, event):
  53. painter = QPainter(self)
  54. event.accept()
  55. if not self.isEnabled():
  56. painter.save()
  57. painter.setOpacity(0.2)
  58. painter.drawPixmap(self.fPixmapRect, self.fPixmapNormal, self.fPixmapRect)
  59. painter.restore()
  60. elif self.isChecked() or self.isDown():
  61. painter.drawPixmap(self.fPixmapRect, self.fPixmapDown, self.fPixmapRect)
  62. elif self.fIsHovered:
  63. painter.drawPixmap(self.fPixmapRect, self.fPixmapHover, self.fPixmapRect)
  64. else:
  65. painter.drawPixmap(self.fPixmapRect, self.fPixmapNormal, self.fPixmapRect)