разворачивание и сворачивание groupbox pyside6

Рейтинг: 0Ответов: 0Опубликовано: 26.02.2023

можно ли как-то реализовать данную функцию, чтобы по нажатию groupbox разворачивался и назад

from PySide6 import QtCore, QtGui, QtWidgets

class SettingPage(QtWidgets.QWidget):

def __init__(self, parent=None):
    QtWidgets.QWidget.__init__(self, parent)
    self.ui = parent
    
    self.initialize()
    
def initialize(self):
    
    self.ui.toolButton.setStyleSheet("""
        QToolButton { 
            border: 2px solid #09009B;
            border-radius: 4px;
            min-width:  145px;
            min-height:  30px;
        }
        QToolButton::checked { 
            border: 2px solid #ff009B;
        }    
    """)
    
    self.ui.toolButton.setToolButtonStyle(
        QtCore.Qt.ToolButtonTextBesideIcon
    )
    
    self.ui.toolButton.setArrowType(QtCore.Qt.RightArrow)
    self.ui.toolButton.pressed.connect(self.on_pressed)
    self.toggle_animation = QtCore.QParallelAnimationGroup(self)

    self.toggle_animation.addAnimation(
        QtCore.QPropertyAnimation(self, b"minimumHeight")
    )
    self.toggle_animation.addAnimation(
        QtCore.QPropertyAnimation(self, b"maximumHeight")
    )
    self.toggle_animation.addAnimation(
        QtCore.QPropertyAnimation(self.ui.groupBox_12, b"maximumHeight")
    )
    
    self.ui.groupBox_12.setSizePolicy(
        QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed
    )
    # self.ui.groupBox_12.setFrameShape(QtWidgets.QFrame.NoFrame)

    self.setContentLayout(self.ui.groupBox_12, QtWidgets.QVBoxLayout())
    
    
@QtCore.Slot()
def on_pressed(self):
    checked = self.ui.toolButton.isChecked()
    self.ui.toolButton.setArrowType(
        QtCore.Qt.DownArrow if not checked else QtCore.Qt.RightArrow
    )
    self.toggle_animation.setDirection(
        QtCore.QAbstractAnimation.Forward
        if not checked
        else QtCore.QAbstractAnimation.Backward
    )
    self.toggle_animation.start()
    
    
    
    
def setContentLayout(self, area, layout):
    lay = area.layout()
    del lay
    area.setLayout(layout)
    collapsed_height = (
        self.sizeHint().height() + area.maximumHeight()
    )
    content_height = layout.sizeHint().height()
    for i in range(self.toggle_animation.animationCount()):
        animation = self.toggle_animation.animationAt(i)
        animation.setDuration(500)
        animation.setStartValue(collapsed_height)
        animation.setEndValue(collapsed_height + content_height)

    content_animation = self.toggle_animation.animationAt(
        self.toggle_animation.animationCount() - 1
    )
    content_animation.setDuration(500)
    content_animation.setStartValue(0)
    content_animation.setEndValue(content_height)

введите сюда описание изображения

Ответы

Ответов пока нет.