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

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