1

I have struggle with animation. It works first time to increase width but with else statements it doesnt' decrease size.

def slideLeftMenu(self):
        self.animation=QPropertyAnimation(self.ui.LeftMenuContainer,b'minimumWidth')
        self.animation.setDuration(250)
       
        width=self.ui.LeftMenuContainer.width()
      
    
       
        if width==50:
            
            self.ui.mainBodyContainer.move(100,0)
            self.animation.setStartValue(50)
            self.animation.setEndValue(100)
            self.animation.start()
            
        else:
             self.ui.mainBodyContainer.move(50,0)
             self.animation.setStartValue(100)
             self.animation.setEndValue(50)
             self.animation.setEasingCurve(QtCore.QEasingCurve.Type.InOutQuart)
             self.animation.start()
cryg0
  • 55
  • 1
  • 6
  • 1
    Setting the minimum width only changes the size if the current width is smaller. Use a QVariantAnimation connected to `self.ui.LeftMenuContainer.setFixedWidth`. – musicamante Apr 29 '22 at 17:22

1 Answers1

1

Try this:

def slideLeftMenu(self):
    # GET WIDTH
    width = self.ui.LeftMenuContainer.width()
    widthExtended = 50

    # SET MAX WIDTH
    if width == 50:
        widthExtended = 100

    # ANIMATION
    self.animation = QtCore.QPropertyAnimation(self.frame_left_menu, b"minimumWidth")
    self.animation.setDuration(250)
    self.animation.setStartValue(50)
    self.animation.setEndValue(widthExtended)
    self.animation.setEasingCurve(QtCore.QEasingCurve.Type.InOutQuart)
    self.animation.start()
zeroalpha
  • 173
  • 1
  • 11