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 3.1KB

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
11 years ago
11 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 PyQt4.QtCore import QPointF, QRectF
  20. from PyQt4.QtGui import QColor, QFont, 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.fTopText = ""
  32. self.fTopTextColor = QColor()
  33. self.fTopTextFont = QFont()
  34. self.setText("")
  35. def setPixmaps(self, normal, down, hover):
  36. self.fPixmapNormal.load(normal)
  37. self.fPixmapDown.load(down)
  38. self.fPixmapHover.load(hover)
  39. width = self.fPixmapNormal.width()
  40. height = self.fPixmapNormal.height()
  41. self.fPixmapRect = QRectF(0, 0, width, height)
  42. self.setMinimumSize(width, height)
  43. self.setMaximumSize(width, height)
  44. def setTopText(self, text, color, font):
  45. self.fTopText = text
  46. self.fTopTextColor = color
  47. self.fTopTextFont = font
  48. def enterEvent(self, event):
  49. self.fIsHovered = True
  50. QPushButton.enterEvent(self, event)
  51. def leaveEvent(self, event):
  52. self.fIsHovered = False
  53. QPushButton.leaveEvent(self, event)
  54. def paintEvent(self, event):
  55. painter = QPainter(self)
  56. event.accept()
  57. if not self.isEnabled():
  58. painter.save()
  59. painter.setOpacity(0.2)
  60. painter.drawPixmap(self.fPixmapRect, self.fPixmapNormal, self.fPixmapRect)
  61. painter.restore()
  62. elif self.isChecked() or self.isDown():
  63. painter.drawPixmap(self.fPixmapRect, self.fPixmapDown, self.fPixmapRect)
  64. elif self.fIsHovered:
  65. painter.drawPixmap(self.fPixmapRect, self.fPixmapHover, self.fPixmapRect)
  66. else:
  67. painter.drawPixmap(self.fPixmapRect, self.fPixmapNormal, self.fPixmapRect)
  68. if not self.fTopText:
  69. return
  70. painter.save()
  71. painter.setPen(self.fTopTextColor)
  72. painter.setBrush(self.fTopTextColor)
  73. painter.setFont(self.fTopTextFont)
  74. painter.drawText(QPointF(10, 16), self.fTopText)
  75. painter.restore()