Движение прямоугольника в qt

не двигается прямоугольник, который рисую, и не понимаю почему... Помогите пожалуйста исправить эту ошибку

//rectangle.h

#include <QWidget>
#include <QPainter>
#include <QApplication>
#include <QPropertyAnimation>


QT_BEGIN_NAMESPACE
namespace Ui { class rectangle; }
QT_END_NAMESPACE

class rectangle : public QWidget
{
    Q_OBJECT

public:
    rectangle(QWidget *parent = nullptr);
    ~rectangle();

   // rectangle *myRect;
    void paintEvent(QPaintEvent *e);
    void moving(QObject* object);


private:
    Ui::rectangle *ui;

    QPoint origin;
    QSize size;
    int step = 10;
};
#endif // RECTANGLE_H






//rectangle.cpp
#include "rectangle.h"
#include "ui_rectangle.h"

rectangle::rectangle(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::rectangle)
{
    ui->setupUi(this);

    size = QSize(200,100);
    origin = QPoint(500,50);

}

void rectangle::moving(QObject* object) {
    QPoint end(50,50);    
        

   if(auto* a =new QPropertyAnimation(object, "pos"))
        {
            a->setDuration(3000);
            a->setStartValue(origin);
            a->setEndValue(end);
            a->start(QAbstractAnimation::DeleteWhenStopped);
        }

}


void rectangle::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    
    QPainter painter(this);
    painter.fillRect(QRect(origin,size), QColor(Qt::green));
    }

rectangle::~rectangle()
{
    delete ui;
}








//main.cpp
#include "rectangle.h"

#include <QApplication>
#include <QDebug>
#include <QPaintEvent>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    rectangle w;
    w.resize({800,600});

    w.show();
    return a.exec();
}



Ответы (0 шт):