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_OBJECT
      Q_PROPERTY(QColor color READ color WRITE setColor)
    
    public:
      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(color.red()).arg(color.green()).arg(color.blue()));
      }
      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();
         ui->treeWidget->viewport()->setGraphicsEffect(effect);
    
    .....
    
    QPropertyAnimation *animation = new QPropertyAnimation(effect, "color");
        animation->setDuration(2000);
        animation->setStartValue(QColor(255, 0, 0));
        animation->setEndValue(QColor(0, 255, 0));
        animation->start();
    

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


  • Qt Champions 2016



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


  • Qt Champions 2016

    @slenderwrist
    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.


  • Qt Champions 2016

    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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.