#include <QtGui>
{
Q_OBJECT
public:
resize(200, 200);
// Start a slide on to the screen
QPropertyAnimation *slideIn = new QPropertyAnimation(this, "pos");
slideIn->setEasingCurve(QEasingCurve(QEasingCurve::OutQuad)); // optional, linear by default
slideIn->setDuration(5000);
slideIn
->setStartValue
(QPoint(-200,
-200));
slideIn
->setEndValue
(QPoint(0,
0));
slideIn->start();
connect(slideIn, SIGNAL(finished()), SLOT(slideInFinished()));
connect(slideIn, SIGNAL(finished()), slideIn, SLOT(deleteLater()));
}
private slots:
void slideInFinished() {
// Organise to wait a while
QTimer::singleShot(3000,
this,
SLOT(pauseFinished
()));
}
void pauseFinished() {
// Done waiting, let's leave
QPropertyAnimation *slideOut = new QPropertyAnimation(this, "pos");
slideOut->setEasingCurve(QEasingCurve(QEasingCurve::InQuad));
slideOut->setDuration(5000);
slideOut
->setStartValue
(QPoint(0,
0));
slideOut
->setEndValue
(QPoint(-200,
-200));
slideOut->start();
connect(slideOut, SIGNAL(finished()), SLOT(slideOutFinished()));
connect(slideOut, SIGNAL(finished()), slideOut, SLOT(deleteLater()));
}
void slideOutFinished() {
qApp->quit();
}
};
int main(int argc, char **argv)
{
SelfAnimator w;
w.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
class SelfAnimator: public QWidget
{
Q_OBJECT
public:
SelfAnimator(QWidget *p = 0): QWidget(p) {
resize(200, 200);
// Start a slide on to the screen
QPropertyAnimation *slideIn = new QPropertyAnimation(this, "pos");
slideIn->setEasingCurve(QEasingCurve(QEasingCurve::OutQuad)); // optional, linear by default
slideIn->setDuration(5000);
slideIn->setStartValue(QPoint(-200, -200));
slideIn->setEndValue(QPoint(0, 0));
slideIn->start();
connect(slideIn, SIGNAL(finished()), SLOT(slideInFinished()));
connect(slideIn, SIGNAL(finished()), slideIn, SLOT(deleteLater()));
}
private slots:
void slideInFinished() {
// Organise to wait a while
QTimer::singleShot(3000, this, SLOT(pauseFinished()));
}
void pauseFinished() {
// Done waiting, let's leave
QPropertyAnimation *slideOut = new QPropertyAnimation(this, "pos");
slideOut->setEasingCurve(QEasingCurve(QEasingCurve::InQuad));
slideOut->setDuration(5000);
slideOut->setStartValue(QPoint(0, 0));
slideOut->setEndValue(QPoint(-200, -200));
slideOut->start();
connect(slideOut, SIGNAL(finished()), SLOT(slideOutFinished()));
connect(slideOut, SIGNAL(finished()), slideOut, SLOT(deleteLater()));
}
void slideOutFinished() {
qApp->quit();
}
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
SelfAnimator w;
w.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks