Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在qt中设置QPushButton背景色的动画?_Python_C++_Qt_Animation_Pyqt4 - Fatal编程技术网

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