簡體   English   中英

如何在Qt中設置QPushButton的背景色的動畫?

[英]How to animate the background color of a QPushButton in qt?

我做了一切[直到我所知道的]來為按鈕的背景色設置動畫,但是我做不到。 這是我的嘗試之一:

    # 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(“ background-color:blue”))TypeError:PyQt4.QtGui.QStyle表示一個C ++抽象類,無法實例化

我還嘗試設置一個調色板:

    color = install_btn.palette()
    color.setColor(QPalette.Base,QColor(72, 152, 219))
    install_btn.setAutoFillBackground(True)
    install_btn.setPalette(color)

然后我寫了QColor(r,g,b)而不是上面的動畫值中的QStyle ,但是它也沒有用,它說:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM