Search code examples
c++qtqmovie

How to rotate/transform QMovie in c++


I can rotate QPixmap with code like this

  QPixmap pix("img.jpg");
  QMatrix rm;
  rm.rotate(90);
  pix = pix.transformed(rm)

how can I do same with QMovie? Or somehow wrap it into some "container" and rotate that "container"?


Solution

  • You can try to rotate frame by frame. For example:

    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 rotate every frame when frame changed

    void MainWindow::OnFrameChanged(int /*frame*/)
    {
        QPixmap pixmap = m_movie->currentPixmap();
        QMatrix rm;
        rm.rotate(90);
        pixmap = pixmap.transformed(rm);
        ui->lblMovRotated->setPixmap(pixmap);
    }