removed current implementation of CollapsibleWidget

This commit is contained in:
iLLiCiTiT 2021-04-28 16:02:44 +02:00
parent f1f4f2afd2
commit 17ae9af094

View file

@ -427,101 +427,6 @@ class InstallDialog(QtWidgets.QDialog):
return super(InstallDialog, self).closeEvent(event)
class CollapsibleWidget(QtWidgets.QWidget):
"""Collapsible widget to hide mongo url in necessary."""
def __init__(self, parent=None, title: str = "", animation: int = 300):
self._mainLayout = QtWidgets.QGridLayout(parent)
self._toggleButton = QtWidgets.QToolButton(parent)
self._headerLine = QtWidgets.QFrame(parent)
self._toggleAnimation = QtCore.QParallelAnimationGroup(parent)
self._contentArea = QtWidgets.QScrollArea(parent)
self._animation = animation
self._title = title
super(CollapsibleWidget, self).__init__(parent)
self._init_ui()
def _init_ui(self):
self._toggleButton.setStyleSheet(
"""QToolButton {
border: none;
}
""")
self._toggleButton.setToolButtonStyle(
QtCore.Qt.ToolButtonTextBesideIcon)
self._toggleButton.setArrowType(QtCore.Qt.ArrowType.RightArrow)
self._toggleButton.setText(self._title)
self._toggleButton.setCheckable(True)
self._toggleButton.setChecked(False)
self._headerLine.setFrameShape(QtWidgets.QFrame.HLine)
self._headerLine.setFrameShadow(QtWidgets.QFrame.Sunken)
self._headerLine.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Maximum)
self._contentArea.setStyleSheet(
"""QScrollArea {
background-color: rgb(32, 32, 32);
border: none;
}
""")
self._contentArea.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Fixed)
self._contentArea.setMaximumHeight(0)
self._contentArea.setMinimumHeight(0)
self._toggleAnimation.addAnimation(
QtCore.QPropertyAnimation(self, b"minimumHeight"))
self._toggleAnimation.addAnimation(
QtCore.QPropertyAnimation(self, b"maximumHeight"))
self._toggleAnimation.addAnimation(
QtCore.QPropertyAnimation(self._contentArea, b"maximumHeight"))
self._mainLayout.setVerticalSpacing(0)
self._mainLayout.setContentsMargins(0, 0, 0, 0)
row = 0
self._mainLayout.addWidget(
self._toggleButton, row, 0, 1, 1, QtCore.Qt.AlignCenter)
self._mainLayout.addWidget(
self._headerLine, row, 2, 1, 1)
row += row
self._mainLayout.addWidget(self._contentArea, row, 0, 1, 3)
self.setLayout(self._mainLayout)
self._toggleButton.toggled.connect(self._toggle_action)
def _toggle_action(self, collapsed: bool):
arrow = QtCore.Qt.ArrowType.DownArrow if collapsed else QtCore.Qt.ArrowType.RightArrow # noqa: E501
direction = QtCore.QAbstractAnimation.Forward if collapsed else QtCore.QAbstractAnimation.Backward # noqa: E501
self._toggleButton.setArrowType(arrow)
self._toggleAnimation.setDirection(direction)
self._toggleAnimation.start()
def setContentLayout(self, content_layout: QtWidgets.QLayout): # noqa
self._contentArea.setLayout(content_layout)
collapsed_height = \
self.sizeHint().height() - self._contentArea.maximumHeight()
content_height = self._contentArea.sizeHint().height()
for i in range(self._toggleAnimation.animationCount() - 1):
sec_anim = self._toggleAnimation.animationAt(i)
sec_anim.setDuration(self._animation)
sec_anim.setStartValue(collapsed_height)
sec_anim.setEndValue(collapsed_height + content_height)
con_anim = self._toggleAnimation.animationAt(
self._toggleAnimation.animationCount() - 1)
con_anim.setDuration(self._animation)
con_anim.setStartValue(0)
con_anim.setEndValue(collapsed_height + content_height)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
d = InstallDialog()