PySide QPropertyAnimation无法启动 [英] PySide QPropertyAnimation Not Starting

查看:445
本文介绍了PySide QPropertyAnimation无法启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是,当我叫 QPropertyAnimation.start(),什么都不会发生。

The problem is that when I call QPropertyAnimation.start(), nothing happens.

颜色是我在动画的属性和按钮的类。

Color is the property I'm animating and button is the class.

class Button(QPushButton):
    def __init__(self,text="",parent=None):
        super(Button,self).__init__(text,parent)
        # ...
        self.innercolor = QColor(200,0,20)

    def setcolor(self,value): self.innercolor = value
    def getcolor(self): return self.innercolor
    color = Property(QColor,getcolor,setcolor)

    def paintEvent(self, event):
        p = QPainter(self)
        p.fillRect(self.rect(),self.color)
        # ...
        p.end()

    def animated(self,value): print "animating"; self.update()

    def enterEvent(self, event):
        ani = QPropertyAnimation(self,"color")
        ani.setStartValue(self.color)
        ani.setEndValue(QColor(0,0,10))
        ani.setDuration(2000)
        ani.valueChanged.connect(self.animated)
        ani.start()
        print ani.state()
        return QPushButton.enterEvent(self, event)

我很困惑,因为动画从来没有打印出来,但 ani.state()表示,动画正在运行。

I'm confused because "animating" never prints out, but ani.state() says the animation is running.

我不要求调试我的code或什么,但我想一定有什么我失踪,无论是在我的code或我使用 QPropertyAnimation 。

I'm not asking to debug my code or anything, but I think there must be something I'm missing, either in my code or in my understanding of the use of QPropertyAnimation.

我搜索谷歌的答案,但无论如何没有来了,没有什么与我有关。我发现的最接近是另一SO质疑,但我还是不能把它转换成给自己一个答案。我也看到了一些关于自定义插值,做我需要做一个定制的插补器,如果是这样,我怎么做。

I've searched google for an answer, but nothing came up, nothing relevant to me anyway. The closest I found was another SO question, but I still couldn't turn that into an answer for myself. I also saw something about a custom interpolator, do I need to make a custom interpolator, if so, how do I do that.

推荐答案

酷code。它几乎工作,但动画不是持久的过去enterEvent(虽然我不完全理解的机制。)如果更改

Cool code. It almost works, but the animation isn't persisting past the enterEvent (although I don't entirely understand the mechanics.) If you change

ani = QPropertyAnimation(self,"color")

self.ani = QPropertyAnimation(self, "color")
# etc

那么它会工作。

这篇关于PySide QPropertyAnimation无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆