如何在qt中设置QPushButton的背景色动画?

2024-05-19 05:21:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我做了一切[直到我知道]动画的背景色按钮,但我做不到。以下是我的一个尝试:

    # 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()

但以下代码显示以下错误:

动画.setStartValue(QStyle(“背景-颜色:蓝色")) 类型错误:PyQt4。QtGui.QStyle型表示C++抽象类,不能实例化>/P>

我还试图设置一个调色板:

^{pr2}$

然后我在上面的动画值中写了QColor(r,g,b),而不是QStyle,但这也没用,它说:

QPropertyAnimation:您正在尝试为QObject的不存在的属性样式设置动画

请用你所知道的任何语言(C++或Python)来帮助我。但我用Python。在

谢谢是特别的


Tags: ofthestyle错误动画按钮colorbackground
1条回答
网友
1楼 · 发布于 2024-05-19 05:21:21

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();

相关问题 更多 >

    热门问题