QT window Animation (SAG, jitter, transparency)

Source: Internet
Author: User

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
      • Effect
      • Source
    • 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.