gpt4 book ai didi

python - PySide QPropertyAnimation 未启动

转载 作者:太空宇宙 更新时间:2023-11-03 18:51:22 25 4
gpt4 key购买 nike

问题是当我调用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 ,但我仍然无法将其转化为自己的答案。我还看到了一些关于自定义插值器的内容,我是否需要制作自定义插值器,如果需要,我该怎么做。

最佳答案

很酷的代码。它几乎可以工作,但是动画不会在 EnterEvent 之后持续存在(尽管我不完全理解其机制。)如果您更改

ani = QPropertyAnimation(self,"color")

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

然后就可以了。

关于python - PySide QPropertyAnimation 未启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18291726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com