QPushButton *btn = new QPushButton("Button", this); btn->setGeometry(10, 10, 100, 30); QPropertyAnimation *animation; animation = new QPropertyAnimation(btn, "geometry", this); animation->setDuration(3000);//從起始座標到結束座標的時長[單位ms]3s,默認250ms animation->setStartValue(QRect(10, 10, 100, 30)); //設置起始座標 animation->setEndValue(QRect(200, 150, 100, 30)); //結束座標,當座標值改變時,會發生valueChanged信號事件 animation->start();