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.

collapsablewidget.py 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Collapsible Box, a custom Qt widget
  4. # Copyright (C) 2019 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 pyqtSlot, Qt
  20. from PyQt5.QtGui import QCursor, QFont
  21. from PyQt5.QtWidgets import QFrame, QSizePolicy, QToolButton, QVBoxLayout, QWidget
  22. # ------------------------------------------------------------------------------------------------------------
  23. # Widget Class
  24. class QToolButtonWithMouseTracking(QToolButton):
  25. def __init__(self, parent):
  26. QToolButton.__init__(self, parent)
  27. self._font = self.font()
  28. def enterEvent(self, event):
  29. self._font.setBold(True)
  30. self.setFont(self._font)
  31. QToolButton.enterEvent(self, event)
  32. def leaveEvent(self, event):
  33. self._font.setBold(False)
  34. self.setFont(self._font)
  35. QToolButton.leaveEvent(self, event)
  36. class CollapsibleBox(QFrame):
  37. def __init__(self, title, parent):
  38. QFrame.__init__(self, parent)
  39. self.setFrameShape(QFrame.StyledPanel)
  40. self.setFrameShadow(QFrame.Raised)
  41. self.toggle_button = QToolButtonWithMouseTracking(self)
  42. self.toggle_button.setText(title)
  43. self.toggle_button.setCheckable(True)
  44. self.toggle_button.setChecked(True)
  45. self.toggle_button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
  46. self.toggle_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
  47. self.toggle_button.setArrowType(Qt.DownArrow)
  48. self.toggle_button.toggled.connect(self.toolButtonPressed)
  49. self.content_area = QWidget(self)
  50. self.content_layout = QVBoxLayout(self.content_area)
  51. self.content_layout.setContentsMargins(6, 2, 6, 0)
  52. self.content_layout.setSpacing(3)
  53. lay = QVBoxLayout(self)
  54. lay.setContentsMargins(0, 0, 0, 4)
  55. lay.setSpacing(1)
  56. lay.addWidget(self.toggle_button)
  57. lay.addWidget(self.content_area)
  58. @pyqtSlot(bool)
  59. def toolButtonPressed(self, toggled):
  60. self.content_area.setVisible(toggled)
  61. self.toggle_button.setArrowType(Qt.DownArrow if toggled else Qt.RightArrow)
  62. def getContentLayout(self):
  63. return self.content_layout