Briefly
In the previous sections we introduced the basic use of animations, animated animation, string action drawing groups, and parallel animation groups. In this section we will implement some special effects to make the interaction smoother.
- Briefly
- Example
- More references
Example
Below, we take the geometry, POS, windowopacity attributes as an example to achieve the form's drop, jitter, transparency effect.
Effect
Source
Drop Effect:
Set the start and end values of the animation by calculating the width and height of the desktop.
voidMainWindow:: Ondropwindow() {Qpropertyanimation*Panimation= NewQpropertyanimation (This,"Geometry"); Qdesktopwidget*Pdesktopwidget=Qapplication::d esktop(); int x=(Pdesktopwidget -Availablegeometry ().Width ()-Width ())/ 2; int y=(Pdesktopwidget -Availablegeometry ().Height ()-Height ())/ 2; Panimation -Setduration ( +); Panimation -Setstartvalue (Qrect (x,0, Width (), height ())); Panimation -Setendvalue (Qrect (x, Y, Width (), height ())); Panimation -Seteasingcurve (Qeasingcurve:: Outelastic); Panimation -Start (qabstractanimation::D eletewhenstopped);}
Jitter Effect:
The coordinates of the interface are obtained, then the top, bottom, left, and right coordinates are floated, and the position of each moment is set by Setkeyvalueat () to achieve the jitter effect.
void MainWindow:: Onshakewindow () {qpropertyanimation *panimation = new Qpropertyanimation (This, "POS");Panimation->setduration ($); 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::D eletewhenstopped);}
Transparency Effect:
The
Sets the transparency value for each moment, and restores the interface at the end of the animation (1 transparency).
void mainwindow: : Onopacitywindow () {qpropertyanimation * panimation = new Qpropertyanimation (This, "windowopacity" ); Panimation-> setduration (1000 ); Panimation-> setkeyvalueat (0 , 1 ); Panimation-> setkeyvalueat (0.5 , 0 ); Panimation-> setkeyvalueat (1 , 1 ); Panimation-> start (Qabstractanimation);}
is not very interesting, but also hurry up, to achieve their own animation.
More references
- QT's animated frame
- The qpropertyanimation of QT
- The Qsequentialanimationgroup of QT
- The Qparallelanimationgroup of QT
- The qpauseanimation of QT
QT window Animation (SAG, jitter, transparency)