Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTreeWidgetItem animate backgorund color
Qt 6.11 is out! See what's new in the release blog

QTreeWidgetItem animate backgorund color

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    slenderwrist
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Did you try with
      http://doc.qt.io/qt-5/qtreewidgetitem.html#setBackground

      1 Reply Last reply
      0
      • S Offline
        S Offline
        slenderwrist
        wrote on last edited by
        #3

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

        mrjjM 1 Reply Last reply
        0
        • S slenderwrist

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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • S Offline
            S Offline
            slenderwrist
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              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.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved