import os import sys from PySide2.QtCore import * from PySide2.QtGui import * from PySide2.QtWidgets import * class MainWindow(QDialog): def __init__(self, parent = None): QDialog.__init__(self, parent) # Init settings self.setStyleSheet("QWidget{ background-color: rgba(0,0,0);}") self.groupLyt = QGridLayout() self.procSessBrwsr = ProcBrowserWidget(self) self.collapseProcBrowserBtn = QToolButton() self.collapseProcBrowserBtn.clicked.connect(self.collapseProcBrowser) self.collapseProcBrowserBtn.setText("Toggle List View") self.collapseProcBrowserBtn.setStyleSheet("QToolButton { font-size: 12pt; color:white; background: gray;}") self.groupLyt.addWidget( self.procSessBrwsr, 0, 0, -1, 1, Qt.AlignLeft) self.groupLyt.addWidget( self.collapseProcBrowserBtn, 0, 0, 1, 1, Qt.AlignLeft) self.groupLyt.setContentsMargins(1,1,1,1) self.groupLyt.setRowStretch(0,1) self.groupLyt.setRowStretch(1,99) self.setLayout(self.groupLyt) self.resize(800,600) self.show() def collapseProcBrowser(self): if self.procSessBrwsr.panelIsClosed == False: self.collapseProcBrowserBtn.setText("") else: self.collapseProcBrowserBtn.setText("Toggle List View") self.procSessBrwsr.collapseToggle() class ProcBrowserWidget(QWidget): def __init__(self, parent = None ): QWidget.__init__(self , parent) self.parent = parent self.panelIsClosed = False self.spacerWidget = QToolButton() self.browserList = QListWidget(self) self.browserList.addItems(['Item A - Some Item', 'Item B - Some Item', 'Item C - Some Item', \ 'Item D - Some Item', 'Item E - Some Item', 'Item F - Some Item', \ 'Item G - Some Item', 'Item H - Some Item', 'Item I - Some Item', \ 'Item J - Some Item', 'Item K - Some Item', 'Item L - Some Item']) self.mainLyt = QGridLayout() self.mainLyt.setContentsMargins(0,0,0,0) self.mainLyt.addWidget(self.spacerWidget, 0, 0, Qt.AlignTop) self.mainLyt.addWidget(self.browserList , 1, 0) self.setLayout(self.mainLyt) self.setStyleSheet("QListWidget {\ background-color: rgba(20,20,20,240);\ font-size: 12pt;\ border-radius: 0px;\ border: 0px;}\n\ QListWidget::item { border: 0px; color: rgb(180,180,180);}\n\ QListWidget::item:selected {\ background-color:transparent;color:white;}\n\ QListWidget::item:hover {\ color:white;}" ) def collapseToggle(self, duration = 100): localRec = self.geometry() if self.panelIsClosed == False: self.panelIsClosed = True self.hide() destRect = QRect( QPoint(self.geometry().topLeft().x(), self.geometry().topLeft().y()), \ QSize( 32, self.height() ) ) opStart = 1 opEnd = 0 else: self.show() self.panelIsClosed = False destRect = QRect( QPoint(self.geometry().topLeft().x() + 1 , self.geometry().topLeft().y()), \ QSize( 200 , self.height() - 1 ) ) opStart = 0 opEnd = 1 # Set Widget Size Animation self.animation = QPropertyAnimation(self, "geometry") self.animation.setDuration( duration ) self.animation.setStartValue( localRec ) self.animation.setEndValue( destRect ) self.animation.setEasingCurve(QEasingCurve.InOutQuad) self.animation.start() self.animation.finished.connect(self.animFinished) # Set Widget Opacity Animation fadeEffect = QGraphicsOpacityEffect(self.browserList); self.browserList.setGraphicsEffect(fadeEffect) self.animationOP = QPropertyAnimation(fadeEffect, "opacity") self.animationOP.setDuration( duration ) self.animationOP.setStartValue( opStart ) self.animationOP.setEndValue( opEnd ) self.animationOP.start() def animFinished(self): if self.panelIsClosed == True: self.hide() if __name__ == '__main__': try: QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) except Exception as e: pass app = QApplication(sys.argv) mainWin = MainWindow() sys.exit(app.exec_())