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.5KB

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