Important: Please read the Qt Code of Conduct -

QTreeWidgetItem animate backgorund color

  • Hİ, i am trying to add background-color change animation to QTreeWidgetItems.

    I have subclassed QtreeWidgetItem:

    class CustomQTreeWidgetItem : public QWidget, public QTreeWidgetItem
      Q_PROPERTY(QColor color READ color WRITE setColor)
      CustomQTreeWidgetItem(const QStringList &strings, int type = Type) :  QTreeWidgetItem(strings, type)
      CustomQTreeWidgetItem(QTreeWidget *parent, const QStringList &strings, int type = Type) :  QTreeWidgetItem(parent, strings, type)
      void setColor (QColor color){
        setStyleSheet(QString("background-color: rgb(%1, %2, %3);").arg(;
      QColor color(){
        return Qt::black; // getter is not really needed for now

    And this is what i have on mainwindow.cpp

     QGraphicsColorizeEffect *effect = new QGraphicsColorizeEffect();
    QPropertyAnimation *animation = new QPropertyAnimation(effect, "color");
        animation->setStartValue(QColor(255, 0, 0));
        animation->setEndValue(QColor(0, 255, 0));

    Instead of backgorund color change animation this animates the color of the text of my treewidgetItems, any ideas ?

  • Lifetime Qt Champion

  • i want color changing as animation, setBackground changes instantly i think.

  • Lifetime Qt Champion

    Well if you set different brushes it will/should be animated. Just like Color set the text color.

  • I tried it with different brushes it just sets background-color no animation. maybe i explained myself badly. i want the treewidgetitem's backgorund color to start as red then gradually turn to green within the duration. I tried to copy the solution from this link stackoverflow-similiar-problem. but instead of backgorund color, text color animates. my code is in the first post.

  • Lifetime Qt Champion

    Ok, but text also just sets the text color.
    If you create new brush with new color that is exactly the same in my book but
    i didnt try so maybe it does something not expected or the
    QGraphicsColorizeEffect do not work via brushes.

Log in to reply