我正在尝试在 pyqt5 Python 中制作一个按钮,将背景颜色 - 阴影等从浅绿色变为绿色,然后变为深绿色。
我已经尝试了一些代码,但没有。
这是我的代码:
def colorChange(self,button):
self.anim = QPropertyAnimation(button, b"color")
self.anim.setDuration(2500)
self.anim.setLoopCount(2)
self.anim.setStartValue(QColor(0, 0, 0))
self.anim.setEndValue(QColor(255, 255, 255))
self.anim.start()
def eventFilter(self, object, event):
print(int(time.time()-self.first))
if event.type() == QtCore.QEvent.Enter:
if self.stackedWidget.currentIndex()==0:
self.pagelabel1.deleteLater()
print("Mouse is over the label")
self.stop = True
print('program stop is', self.stop)
pick=random.randrange(0,2)
print('random:',pick)
pick=0
if pick==0:
#self.doAnimation(self.right1)
self.colorChange(self.right1)
#self.right1.setStyleSheet("background-color: lightgreen")
self.right1.clicked.connect(self.nextpage)
else:
#self.doAnimation(self.left1)
self.colorChange(self.left1)
#self.left1.setStyleSheet("background-color: lightgreen")
self.left1.clicked.connect(self.nextpage)
我希望 eventFilter 启动动画,动画将是按钮的颜色变化。