Python 如何在qt中设置QPushButton背景色的动画?
我做了一切[直到我知道]动画的背景色的按钮,但我不能这样做。以下是我的一个尝试:Python 如何在qt中设置QPushButton背景色的动画?,python,c++,qt,animation,pyqt4,Python,C++,Qt,Animation,Pyqt4,我做了一切[直到我知道]动画的背景色的按钮,但我不能这样做。以下是我的一个尝试: # I set the style of the button by setstylesheet() animation = QPropertyAnimation(btn, "style",btn) animation.setDuration(1000) animation.setStartValue(QStyle("background-color:blue")) anim
# I set the style of the button by setstylesheet()
animation = QPropertyAnimation(btn, "style",btn)
animation.setDuration(1000)
animation.setStartValue(QStyle("background-color:blue"))
animation.setEndValue(QStyle("background-color:red"))
animation.start()
但以下代码显示以下错误:
animation.setStartValue(QStyle(“背景色:蓝色”))
TypeError:PyQt4.QtGuiqQStype表示C++抽象类,不能实例化>/P>
我还尝试设置调色板:
color = install_btn.palette()
color.setColor(QPalette.Base,QColor(72, 152, 219))
install_btn.setAutoFillBackground(True)
install_btn.setPalette(color)
然后在上面的动画值中,我没有写QStyle
,而是写了QColor(r,g,b)
,但那也不起作用,它说:
QPropertyAnimation:您正在尝试为QObject的不存在的属性样式设置动画
请用您所知道的任何语言(C++或Python)帮助我。但是我使用Python
感谢是特别的C++,Qt5,但可能在Qt4中工作
QGraphicsColorizeEffect *eEffect= new QGraphicsColorizeEffect(btn);
btn->setGraphicsEffect(eEffect);
QPropertyAnimation *paAnimation = new QPropertyAnimation(eEffect,"color");
paAnimation->setStartValue(QColor(Qt::blue));
paAnimation->setEndValue(QColor(Qt::red));
paAnimation->setDuration(1000);
paAnimation->start();
谢谢,但它不起作用:(甚至没有错误。颜色已更改,但其中没有动画。您的代码中是否缺少某些内容?@AhmadTaha我认为您在将代码转换为python时出错。不,我没有,没有错误+我知道一点c++我只是更改rgb中的QColorinstead@AhmadTaha在不更改颜色的情况下尝试此示例
QStyle
是n抽象基类,无法实例化。调色板的背景颜色也不正确。应改用qpalete.Button
。