Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
src_corelib_animation_qpropertyanimation.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QParallelAnimationGroup>
5#include <QSequentialAnimationGroup>
6
7//! [includes]
8#include <QApplication>
9#include <QPushButton>
10#include <QPropertyAnimation>
11
12//![includes]
13
14//! [class_decl]
15class MyButtonWidget : public QWidget
16{
17public:
18 MyButtonWidget(QWidget *parent = nullptr);
19};
20
21//! [class_decl]
22
23//! [ctor_impl]
25{
26//![ctor_impl]
27 {
28 //! [first_example]
29 QPushButton *button = new QPushButton(tr("Animated Button"), this);
30 QPropertyAnimation *anim = new QPropertyAnimation(button, "pos", this);
31 anim->setDuration(10000);
32 anim->setStartValue(QPoint(0, 0));
33 anim->setEndValue(QPoint(100, 250));
34 anim->start();
35 //! [first_example]
36 }
37
38 {
39 //! [easing-curve]
40 QPushButton *button = new QPushButton(tr("Animated Button"), this);
41 QPropertyAnimation *anim = new QPropertyAnimation(button, "pos", this);
42 anim->setDuration(10000);
43 anim->setStartValue(QPoint(0, 0));
44 anim->setEndValue(QPoint(100, 250));
45 anim->setEasingCurve(QEasingCurve::OutBounce);
46 anim->start();
47 //! [easing-curve]
48 }
49
50 {
51 //! [animation-group1]
52 QPushButton *bonnie = new QPushButton(tr("Bonnie"), this);
53 QPushButton *clyde = new QPushButton(tr("Clyde"), this);
54
55 QPropertyAnimation *anim1 = new QPropertyAnimation(bonnie, "pos", this);
56 anim1->setDuration(3000);
57 anim1->setStartValue(QPoint(0, 0));
58 anim1->setEndValue(QPoint(100, 250));
59
60 QPropertyAnimation *anim2 = new QPropertyAnimation(clyde, "pos", this);
61 anim2->setDuration(3000);
62 anim2->setStartValue(QPoint(100, 250));
63 anim2->setEndValue(QPoint(500, 500));
64
65 QParallelAnimationGroup *parallelAnim = new QParallelAnimationGroup;
66 parallelAnim->addAnimation(anim1);
67 parallelAnim->addAnimation(anim2);
68 parallelAnim->start();
69 //! [animation-group1]
70 }
71
72 {
73 //! [animation-group2]
74 QPushButton *bonnie = new QPushButton(tr("Bonnie"), this);
75 QPushButton *clyde = new QPushButton(tr("Clyde"), this);
76
77 QPropertyAnimation *anim1 = new QPropertyAnimation(bonnie, "pos", this);
78 anim1->setDuration(3000);
79 anim1->setStartValue(QPoint(0, 0));
80 anim1->setEndValue(QPoint(100, 250));
81
82 QPropertyAnimation *anim2 = new QPropertyAnimation(clyde, "pos", this);
83 anim2->setDuration(3000);
84 anim2->setStartValue(QPoint(0, 0));
85 anim2->setEndValue(QPoint(200, 250));
86
87 QSequentialAnimationGroup *sequenceAnim = new QSequentialAnimationGroup;
88 sequenceAnim->addAnimation(anim1);
89 sequenceAnim->addAnimation(anim2);
90 sequenceAnim->start();
91 //! [animation-group2]
92 }
93
94//! [ctor_close]
95}
96
97//! [ctor_close]
98
99//! [main]
100int main(int argc, char *argv[])
101{
102 QApplication a(argc, argv);
103 MyButtonWidget buttonAnimWidget;
104 buttonAnimWidget.resize(QSize(800, 600));
105 buttonAnimWidget.show();
106 return a.exec();
107}
108//! [main]
MyButtonWidget(QWidget *parent=nullptr)
[class_decl]
int main(int argc, char *argv[])
[ctor_close]