// ============================================================================ // qt_property_animation —— 教学补充示例(非 wiki 生成,手工维护) // 用途:方案书「C++方向 Day4」要求的 QPropertyAnimation 动画框架,仓库 p03/ // 原有 wiki 抓取内容未覆盖这一点,故补一个最小示例。 // 配套文档:docs/teaching/examples/property_animation/README.md // 离屏验证:QT_QPA_PLATFORM=offscreen tools/run_qt.sh qt_property_animation // ============================================================================ #include #include #include #include #include int main(int argc, char* argv[]) { QApplication app(argc, argv); QWidget window; window.resize(320, 200); auto* button = new QPushButton(QStringLiteral("看我移动"), &window); button->setGeometry(10, 10, 100, 30); // QPropertyAnimation 直接驱动 Qt 属性系统里的 geometry 属性, // 不需要手写定时器 + 逐帧计算坐标。 auto* anim = new QPropertyAnimation(button, "geometry", &window); anim->setDuration(800); anim->setStartValue(QRect(10, 10, 100, 30)); anim->setEndValue(QRect(180, 140, 120, 40)); anim->setEasingCurve(QEasingCurve::OutBounce); anim->start(QAbstractAnimation::DeleteWhenStopped); window.show(); // 离屏/自动化验证:动画时长 800ms,额外等 300ms 确保播放完再退出 QTimer::singleShot(1100, &app, &QApplication::quit); return app.exec(); }