【发布时间】:2013-08-17 17:53:54
【问题描述】:
问题是当我打电话给QPropertyAnimation.start() 时,什么也没有发生。
颜色是我正在制作动画的属性,按钮是类。
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)
我很困惑,因为"animating" 从未打印出来,但ani.state() 表示动画正在运行。
我不是要调试我的代码或任何东西,但我认为我的代码中或我对 QPropertyAnimation 使用的理解中一定有一些我遗漏的东西。
我已经在谷歌上搜索了答案,但没有任何结果,也没有与我相关的内容。我找到的最接近的是another SO question,但我仍然无法将其转化为自己的答案。我还看到了一些关于自定义插值器的东西,我是否需要制作自定义插值器,如果需要,我该怎么做。
【问题讨论】:
-
引用的问题stackoverflow.com/questions/2850957/… 有同样的问题,只是它是一个超出范围的 C++ 局部变量。
标签: python qt animation colors pyside