from PySide6.QtWidgets import ( QApplication, QWidget, QVBoxLayout, QToolButton, QFrame, QLabel, QSizePolicy ) from PySide6.QtCore import Qt class CollapsiblePanel(QWidget): def __init__(self, title="", parent=None): super().__init__(parent) self.toggle_button = QToolButton(text=title, checkable=True, checked=False) self.toggle_button.setStyleSheet("QToolButton { border: none; }") self.toggle_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.toggle_button.setArrowType(Qt.RightArrow) self.toggle_button.clicked.connect(self.on_toggle) self.content_area = QFrame() self.content_area.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.content_area.setMaximumHeight(0) # startowo schowane # Layout panelu layout = QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self.toggle_button) layout.addWidget(self.content_area) def on_toggle(self, checked): if checked: self.toggle_button.setArrowType(Qt.DownArrow) self.content_area.setMaximumHeight(16777215) # odblokuj wysokość else: self.toggle_button.setArrowType(Qt.RightArrow) self.content_area.setMaximumHeight(0) # schowaj if __name__ == "__main__": app = QApplication([]) main = QWidget() layout = QVBoxLayout(main) # Panel 1 panel1 = CollapsiblePanel("Opcje") panel1.content_area.setLayout(QVBoxLayout()) panel1.content_area.layout().addWidget(QLabel("Opcja A")) panel1.content_area.layout().addWidget(QLabel("Opcja B")) # Panel 2 panel2 = CollapsiblePanel("Zaawansowane") panel2.content_area.setLayout(QVBoxLayout()) panel2.content_area.layout().addWidget(QLabel("Parametr 1")) panel2.content_area.layout().addWidget(QLabel("Parametr 2")) layout.addWidget(panel1) layout.addWidget(panel2) layout.addStretch() main.show() app.exec()