QPropertyAnimation doesn't work

qt

Solution

You just didn't copied the example, you also made some changes that broke it. Your `animation` variable is now a local variable that is destroyed at the end of `on_pushButton_clicked` function. Make the QPropertyAnimation instance a member variable of the MainWindow class and use it like this:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow), mAnimation(0)
{
    ui->setupUi(this);
    QPropertyAnimation animation
}

MainWindow::~MainWindow()
{
    delete mAnimation;
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    QPushButton *button = new QPushButton("Animated Button", this);
    button->show();

    mAnimation = new QPropertyAnimation(button, "geometry");
    mAnimation->setDuration(10000);
    mAnimation->setStartValue(QRect(0, 0, 100, 30));
    mAnimation->setEndValue(QRect(250, 250, 100, 30));

    mAnimation->start();
}

Problem

I'm trying to test animations in Qt desktop application. I just copied example from help. After button click, new button just appear in left top corner without animation (even end position is wrong). Am I missing something? Qt 5.0.1, Linux Mint 64bit, GTK ``` #include "mainwindow.h" #include "ui_mainwindow.h" #include <QPropertyAnimation> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { QPushButton *button = new QPushButton("Animated Button", this); button->show(); QPropertyAnimation animation(button, "geometry"); animation.setDuration(10000); animation.setStartValue(QRect(0, 0, 100, 30)); animation.setEndValue(QRect(250, 250, 100, 30)); animation.start(); } ``` Edit: Solved. Animation object must be as global reference. For example in section private QPropertyAnimation *animation. Then QPropertyAnimation = New(....);

Original source