1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| void MainWindow::onShakeWindow() { QPropertyAnimation *pAnimation = new QPropertyAnimation(this, "pos"); pAnimation->setDuration(500); pAnimation->setLoopCount(2); pAnimation->setKeyValueAt(0, QPoint(geometry().x() - 3, geometry().y() - 3)); pAnimation->setKeyValueAt(0.1, QPoint(geometry().x() + 6, geometry().y() + 6)); pAnimation->setKeyValueAt(0.2, QPoint(geometry().x() - 6, geometry().y() + 6)); pAnimation->setKeyValueAt(0.3, QPoint(geometry().x() + 6, geometry().y() - 6)); pAnimation->setKeyValueAt(0.4, QPoint(geometry().x() - 6, geometry().y() - 6)); pAnimation->setKeyValueAt(0.5, QPoint(geometry().x() + 6, geometry().y() + 6)); pAnimation->setKeyValueAt(0.6, QPoint(geometry().x() - 6, geometry().y() + 6)); pAnimation->setKeyValueAt(0.7, QPoint(geometry().x() + 6, geometry().y() - 6)); pAnimation->setKeyValueAt(0.8, QPoint(geometry().x() - 6, geometry().y() - 6)); pAnimation->setKeyValueAt(0.9, QPoint(geometry().x() + 6, geometry().y() + 6)); pAnimation->setKeyValueAt(1, QPoint(geometry().x() - 3, geometry().y() - 3)); pAnimation->start(QAbstractAnimation::DeleteWhenStopped); }
|