0

I'm using gifs in my app. I'd like to only show my gif once and then make it disappear. But it keeps looping and showing again and again.

Here's what I've tried:

    movie = new QMovie(":/in_game/src/countdown.gif");
processLabel = new QLabel();
this->addWidget(processLabel);
processLabel->setStyleSheet("background-color: rgba(0,0,0,0%)");
processLabel->setGeometry(280,250,128,128);

processLabel->setMovie(movie);

int i=0;

if(i<1)
{
    movie->start();
    i++;
}
else
{
    movie->stop();
    processLabel->setEnabled(false);
}

Of course in my .h I've created a QMovie and a QLabel... Any ideas on how to only display once ?

Dom
  • 51
  • 7

1 Answers1

0

You have QMovie::frameCount() method and signal QMovie::frameChanged(). Check your current frame number and stop when current frame become equal QMovie::frameCount()

m_movie = new QMovie(":/gif/tenor.gif");
connect(m_movie, SIGNAL(frameChanged(int)),
        this, SLOT(OnFrameChanged(int)));

ui->lblMovie->setMovie(m_movie);
m_movie->start();

And in slot:

void MainWindow::OnFrameChanged(int frame)
{
    if (frame == m_movie->frameCount() - 1) {
        m_movie->stop();
    }
}
Serhiy Kulish
  • 1,057
  • 1
  • 6
  • 8