Use the QT animation frame to design the fly-in-Disappear special effect
The QT animation framework is very powerful and can be implemented for you as long as you want it. This time I will extract the part of the previous demo for introduction. This section is named "fly in-Disappear", which is mainly used for text display. It is similar to a special effect on PowerPoint.
Check out my demo first. : Here
Original blog, opposed to unauthorized reprinting. Original blog address: http://blog.csdn.net/jiangcaiyang123/article/details/8899279
Some definitions of the flyinvanish class are as follows:
Class flyinvanisheffect: Public qobject // special effect class for flying in and out {q_object q_property (qpointf POS read POS write setpos) Public: flyinvanisheffect (qwidget * pwidget = 0); Virtual ~ Flyinvanisheffect (void); void addtext (const qstring & text); void renderpixmap (qpixmap & pixmap); signals: void start (void); void vanishstart (void); Public slots: void starteffect (void); Private slots: void pausefinished (void); Private: void preparepixmap (const qstring & text); random (qpointf, POS) qstringlist m_stringlist; // string list // The qstate m_initialstate, m_middlestate, m_finalstate; qstatemachine m_machine; // animation part: animated, animated, m_vanishanim; animated; qtimer m_pausetimer; bool m_hasfinished; // plot qpointf m_savedpos; lineargradient m_gradient; qpixmap m_textpixmap; // The parent window pointer qwidget * m_pwidget ;};
Here I define three states and one state machine. I didn't use qfinalstate because the status needs to be switched cyclically. In combination with these statuses, there are several qpropertyanimation instances: m_flyinanim is in charge of the fly, m_riseanim is in charge of the Rise, and m_vanishanim is in charge of the disappear animation. M_riseanim and m_vanishanim are executed in parallel. Therefore, an instance of the qparallelanimationgroup class is required: m_vanishanimgrp. In addition, I tried qpauseanimation. It seems that I cannot combine it with other animations and can only be placed in qsequentialanimationgroup, so I didn't use this class, but used a qtimer for animation latency.
In fact, the principle of this special effect is also very simple: first maintain a string list m_stringlist, then extract the strings one by one, render them into m_textpixmap, and finally perform animation operations on this m_textpixmap. Finally, the lineargradient class inherits from qobject and qlineargradient to implement animation, so there is a way to implement the effect of the disappearance.
When using this function, as long as m_stringlist has elements, you can call starteffect () to implement animation operations. In addition, several judgment statements are added to prevent errors, which are displayed in the CPP file. For details, please download my source code.
The following is another program I created. You can enter any text in the input box and press enter to start the animation. The demo program and source code are provided here.
Demo program: here
Source code: here