Glenn Manalese
Glenn Manalese

Reputation: 41

Change GIF animation speed without generating new QMovie

I am creating a scoreboard for a quiz show and I have stumbled upon this problem. The code below shows that the animation speed of an animated .gif depends on the current score of the player.

    void Scoreboard::label1(int i)
{
    ui->label_46->setNum(i);
    ui->label_46->setStyleSheet("color: #ff5500; qproperty-alignment: AlignCenter; background-color: rgba(0,0,0,0%); font-size: 26 pt;");
    ui->label_96->clear();
    QMovie *logo1 =new QMovie("C:/Users/**REDACTED**/Desktop/esq-minimal-sample-adjusted-color.gif");
    ui->label_96->setMovie(logo1);
    logo1->start();
    int speed;
    speed=i*40;
    if(speed<=0)
    {
        logo1->stop();
       return;
    }else if(speed==100)
    {
        return;
    }else if(speed>500)
    {
        speed=500;
    }
    logo1->setSpeed(speed);
}

The code works fine, until the score has been changed too many times (i.e. the slot label1 has been activated multiple times). This causes multiple copies of the .gif to load at the same place, causing a slowdown of the program.

Is there any way to remove the previous .gif before loading a new .gif to the program?

Upvotes: 3

Views: 438

Answers (1)

Boris Ivanov
Boris Ivanov

Reputation: 4254

Load that Movie once outside that function - in Widget constructor and reuse it multiple times later.

Upvotes: 1

Related Questions