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.

60 lines
2.3KB

  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.QtWidgets import QGroupBox, QSizePolicy, QToolButton, QVBoxLayout, QWidget
  21. # ------------------------------------------------------------------------------------------------------------
  22. # Widget Class
  23. class CollapsibleBox(QGroupBox):
  24. def __init__(self, title, parent):
  25. QGroupBox.__init__(self, parent)
  26. self.toggle_button = QToolButton(self)
  27. self.toggle_button.setText(title)
  28. self.toggle_button.setCheckable(True)
  29. self.toggle_button.setChecked(True)
  30. self.toggle_button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
  31. self.toggle_button.setStyleSheet("border: none;")
  32. self.toggle_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
  33. self.toggle_button.setArrowType(Qt.RightArrow)
  34. self.toggle_button.toggled.connect(self.toolButtonPressed)
  35. self.content_area = QWidget(self)
  36. self.content_layout = QVBoxLayout(self.content_area)
  37. self.content_layout.setContentsMargins(0, 0, 0, 0)
  38. self.content_layout.setSpacing(0)
  39. lay = QVBoxLayout(self)
  40. lay.setContentsMargins(0, 0, 0, 0)
  41. lay.setSpacing(0)
  42. lay.addWidget(self.toggle_button)
  43. lay.addWidget(self.content_area)
  44. @pyqtSlot(bool)
  45. def toolButtonPressed(self, toggled):
  46. self.content_area.setVisible(toggled)
  47. self.toggle_button.setArrowType(Qt.RightArrow if toggled else Qt.DownArrow)
  48. def getContentLayout(self):
  49. return self.content_layout