pyqt6动画不起作用以减小宽度

发布于 2025-01-24 20:25:16 字数 782 浏览 2 评论 0原文

我在动画上挣扎。它首次提高宽度,但虽然否则陈述就不会减小大小。

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()

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()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失而复得 2025-01-31 20:25:16

尝试以下操作:

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()

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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文