Reputation: 1099
I'm trying to use a QLabel to play a gif animation.The gif animation is used for showing loading status. The animation should be played every time when user enters into the scene.
Along with the increased times of entering, The label gets larger. I don't know why.
Here is the simplified code.
the .h file:
#include <QtGui/QMainWindow>
#include "ui_qmovietest.h"
#include <QMovie>
class QMovieTest : public QMainWindow
{
Q_OBJECT
public:
QMovieTest(QWidget *parent = 0, Qt::WFlags flags = 0);
~QMovieTest();
public slots:
void on_pushButton_clicked();
private:
Ui::QMovieTestClass ui;
QMovie* mMovie;
};
here is the .cpp file:
#include "qmovietest.h"
#define PATH ":/QMovieTest/processing.gif"
QMovieTest::QMovieTest(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
mMovie = new QMovie(PATH);
ui.label->setMovie(mMovie);
mMovie->stop();
}
QMovieTest::~QMovieTest()
{
}
void QMovieTest::on_pushButton_clicked()
{
//Pushing a Button represents entering the scene
//Label get larger.
mMovie->setScaledSize(this->size());
mMovie->start();
}
Upvotes: 1
Views: 4157
Reputation: 27611
When the code enters "on_pushButton_clicked", you call
mMovie->setScaledSize(this->size());
According to the documentation for setScaledSize
Sets the scaled frame size to size.
I suspect the window needs to be slightly larger than the frame. As 'this' is the main window, by setting the frame to the size of the window, the window will increase to compensate for the increase in frame size. This will occur each time it enters the on_pushButton_clicked function.
Upvotes: 4