int main(int argc, char **argv) { QApplication app(argc, argv); QWidget panel; QVBoxLayout *l = new QVBoxLayout(&panel); QFrame *viewport = new QFrame; viewport->setFrameShape(QFrame::Box); viewport->setFixedSize(400,600); l->addWidget(viewport); QPushButton *b = new QPushButton("Swap"); l->addWidget(b); QStateMachine machine; QState *s1 = new QState; QState *s2 = new QState; QWidget *w1 = new QCalendarWidget(viewport); w1->setFixedSize(300,500); QWidget *w2 = new QListView(viewport); w2->setFixedSize(300,500); QGraphicsBlurEffect *e1 = new QGraphicsBlurEffect(w1); QGraphicsBlurEffect *e2 = new QGraphicsBlurEffect(w2); w1->setGraphicsEffect(e1); w2->setGraphicsEffect(e2); s1->assignProperty(w1, "pos", QPoint(50,50)); s1->assignProperty(w2, "pos", QPoint(450,50)); s1->assignProperty(e1, "blurRadius", 0); s1->assignProperty(e2, "blurRadius", 15); s2->assignProperty(w1, "pos", QPoint(-350, 50)); s2->assignProperty(w2, "pos", QPoint(50,50)); s2->assignProperty(e1, "blurRadius", 15); s2->assignProperty(e2, "blurRadius", 0); s1->addTransition(b, SIGNAL(clicked()), s2); s2->addTransition(b, SIGNAL(clicked()), s1); machine.addState(s1); machine.addState(s2); QPropertyAnimation *anim1 = new QPropertyAnimation(w1, "pos"); QPropertyAnimation *anim2 = new QPropertyAnimation(w2, "pos"); anim1->setEasingCurve(QEasingCurve::InOutCubic); anim2->setEasingCurve(anim1->easingCurve()); anim1->setDuration(2000); anim2->setDuration(anim1->duration()); machine.addDefaultAnimation(anim1); machine.addDefaultAnimation(anim2); anim1 = new QPropertyAnimation(e1, "blurRadius"); anim2 = new QPropertyAnimation(e2, "blurRadius"); anim1->setDuration(1000); anim2->setDuration(anim1->duration()); machine.addDefaultAnimation(anim1); machine.addDefaultAnimation(anim2); machine.setInitialState(s1); machine.start(); panel.show(); return app.exec(); }
slide from one widget to another