'pyqt6 animation doesnt work for decreasing width
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()
Solution 1:[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()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | zeroalpha |