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. Add Color to Image in Animation (Cross Dissolve Effect)
Forum Updated to NodeBB v4.3 + New Features

Add Color to Image in Animation (Cross Dissolve Effect)

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 401 Views
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1

    Hello all,

    Currently I am trying to have an effect on one of my images where an image goes from being grayscale to having color when a button is clicked. The desired effect I want to achieve is in this gif below:

    ezgif-7-754fc996e6b4.gif
    Essentially, I want a cross dissolve effect

    However, this is not the case right now, as this is how my app is performing. I especially don't like the way the gray image fades out before the color image fades in. Here it is:

    ezgif-7-90350c0e7e28.gif

    Here is my current code. I tried doing something where I used QLabels, the QPropertyAnimation class, and the QGraphicsOpacityEffect class. label is the gray image, while label_2 is the color image:

    Constructor Code:

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),    
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        ui->label_2->setVisible(false);
    }
    

    Button Method:

    void MainWindow::on_pushButton_2_clicked()
    {
        QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
        ui->label->setGraphicsEffect(eff);
        QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
        a->setDuration(4000);
        a->setStartValue(1);
        a->setEndValue(0);
        a->setEasingCurve(QEasingCurve::OutBack);
        a->start(QPropertyAnimation::DeleteWhenStopped);
        connect(a,SIGNAL(finished()),this,SLOT(hideLogo()));
    
        QGraphicsOpacityEffect *eff2 = new QGraphicsOpacityEffect(this);
        ui->label_2->setGraphicsEffect(eff2);
        QPropertyAnimation *a2 = new QPropertyAnimation(eff2,"opacity");
        a2->setDuration(2000);
        a2->setStartValue(0);
        a2->setEndValue(1);
        a2->setEasingCurve(QEasingCurve::InBack);
        ui->label_2->setVisible(true);
        a2->start(QPropertyAnimation::DeleteWhenStopped);
    }
    

    hideLogo slot:

    void MainWindow::hideLogo(){
      ui->label->hide();
    }
    

    If someone could point me to how to better perform a cross dissolve effect (something like what is shown in the first gif), I would be very grateful.

    Note: I am not affiliated with the Boston Celtics in any way; I just typically use their logo for testing purposes.

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #3

      try these easing curves to see if they help.
      https://doc.qt.io/qt-5/qeasingcurve.html#Type-enum
      https://doc.qt.io/qt-5/qvariantanimation.html#easingCurve-prop

      ? 1 Reply Last reply
      1
      • JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by
        #2

        @WesLow said in Add Color to Image in Animation (Cross Dissolve Effect):

        QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
        ui->label->setGraphicsEffect(eff);
        QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
        a->setDuration(4000);
        a->setStartValue(1);
        a->setEndValue(0);
        a->setEasingCurve(QEasingCurve::OutBack);
        a->start(QPropertyAnimation::DeleteWhenStopped);
        connect(a,SIGNAL(finished()),this,SLOT(hideLogo()));
        
            QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
            ui->label->setGraphicsEffect(eff);
            QPropertyAnimation *a = new QPropertyAnimation(eff,"opacity");
            a->setDuration(4000);
            a->setStartValue(1);
            a->setEndValue(0);
            a->setEasingCurve(QEasingCurve::OutBack);
            a->start(QPropertyAnimation::DeleteWhenStopped);
            connect(a,SIGNAL(finished()),this,SLOT(hideLogo()));
        
        one QPropertyAnimation * a is enough. You can toggle start and end values 
        
            a->setStartValue(0);
            a->setEndValue(1);
        

        Can you try to raise duration to see if there is any difference.

        1 Reply Last reply
        0
        • JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #3

          try these easing curves to see if they help.
          https://doc.qt.io/qt-5/qeasingcurve.html#Type-enum
          https://doc.qt.io/qt-5/qvariantanimation.html#easingCurve-prop

          ? 1 Reply Last reply
          1
          • JoeCFDJ JoeCFD

            try these easing curves to see if they help.
            https://doc.qt.io/qt-5/qeasingcurve.html#Type-enum
            https://doc.qt.io/qt-5/qvariantanimation.html#easingCurve-prop

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #4

            @JoeCFD Thank you so much! The InCirc/OutCirc curves worked!

            1 Reply Last reply
            1

            • Login

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