0

I have a frame that expands and shrinks when you click on it. It has 2 Layouts. One layout should be visible whenever the layout is expanded (the content layout), and the other one is supposed to be always visible, even when the frame is shrunken (the header layout).

The content layout is supposed to be resizable horizontally, but is not supposed to resize vertically.

I've tried this, but it didnt work:

class AppDemo(QWidget):
    def __init__(self):
        super().__init__()

        self.frame = QFrame()
        self.frame.setStyleSheet("background: green; border-radius: 8px;")

        self.frame_layout = QVBoxLayout()
        self.frame.setLayout(self.frame_layout)

        self.header_layout = QHBoxLayout()
        self.header_layout.setAlignment(Qt.AlignTop)

        self.content_layout = QVBoxLayout()

        self.frame_layout.addLayout(self.header_layout)
        self.frame_layout.addLayout(self.content_layout)
    

        self.header_label = QLabel(u"Marvin sollte Programmieren lernen!")
        self.header_layout.addWidget(self.header_label)

        self.content_frame = QFrame()
        self.content_frame.setStyleSheet("background: red; border-radius: 8px;")
        self.content_frame.setFixedHeight(1000)
        self.content_layout.addWidget(self.content_frame)


        self.layout = QVBoxLayout()
        self.setLayout(self.layout)
        self.layout.addWidget(self.frame)

        
        self.frame.mouseReleaseEvent = lambda _:self.resizeFrame()

    def resizeFrame(self):        
        current_size = self.frame.geometry()
        
        self.animation = QPropertyAnimation(self.frame, b"geometry")
        self.animation.setDuration(500)
        self.animation.setStartValue(current_size)
        self.animation.setEndValue(QRect(current_size.x(), current_size.y(), current_size.width(), current_size.height() - 500))
        self.animation.setEasingCurve(QEasingCurve.OutCubic)
        self.animation.start()

For refference, I want to achieve an effect like the one that can be seen on this website, when you click on one of the panels to the right.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241

0 Answers0