Briefly
Long ago on the internet to see a pure code implementation of the rotation animation feel very good, share to everyone. I have to say, all roads lead to Rome, we need to create more ...
See: Qprogressindicator
- Briefly
- Effect
- Source
- Use
Effect
Because of the recording program, the GIF effect is not clear, can be ignored.
Source
QProgressIndicator.h
#ifndef Qprogressindicator_h#define QPROGRESSINDICATOR_H#include <QWidget>#include <QColor>/*! \classQprogressindicator \brief the QprogressindicatorclassLets anApplicationDisplay a progress indicator toShow thatA lengthy task isUnder. Progress Indicators is indeterminate andDo nothing more than spin toShow that the Application isBusy. \sa qprogressbar*/classQprogressindicator:public qwidget{q_object q_property (intDelayRead Animationdelay write Setanimationdelay) q_property (bool displayedwhenstopped READ isdisplayedwhenstopped WRITE Set displayedwhenstopped) q_property (qcolor color READ color WRITE setcolor) public:qprogressindicator (qwidget* parent =0); /*! Returns the Delay betweenAnimation steps. \returnThe Number ofMillisecondsbetweenAnimation steps. By default, theAnimationDelay is Set to +Milliseconds. \SA setanimationdelay */int Animationdelay () const {returnM_delay; } /*! Returns a Boolean value indicating whether theComponent isCurrently animated. \returnAnimation state. \sa startanimation stopanimation */BOOL isanimated () const; /*! Returns a Boolean value indicating whether theReceiver shows itself even whenit is notAnimating. \returnReturntrue if theProgress indicator shows itself even whenit is notAnimating. By default,itReturnsfalse. \SA setdisplayedwhenstopped */BOOL isdisplayedwhenstopped () const; /*! Returns theColor of theComponent. \SA SetColor */const Qcolor & Color () const {returnM_color; } virtual Qsize sizehint () const; int heightforwidth (int w) const;public slots:/*! Starts theSpin animation. \sa stopanimation isanimated */void startanimation (); /*! Stops theSpin animation. \sa startanimation isanimated */void stopanimation (); /*! Sets the Delay betweenAnimation steps. Setting the\aDelay toA value larger than +Slows theAnimation whileSetting the\aDelay toA smaller value speedsitUp. \paramDelayTheDelay,inchMilliseconds. \sa Animationdelay */void Setanimationdelay (intDelay); /*! Sets whether theComponent hides itself whenit is notAnimating. \param state, the animation state. Setfalse toHide theProgress indicator whenit is notanimating; otherwisetrue. \sa isdisplayedwhenstopped */void setdisplayedwhenstopped (bool state); /*! Sets theColor of theComponents to the givenColor. \sa color */void SetColor (const qcolor & color);p rotected:virtual void timerevent (Qtimerevent * event); virtual void PaintEvent (Qpaintevent * Event);p Rivate:int M_angle; int M_timerid; int m_delay; BOOL m_displayedwhenstopped; Qcolor M_color;};#endif//Qprogressindicator_h
QProgressIndicator.cpp
#include "QProgressIndicator.h"#include <QPainter>Qprogressindicator::qprogressindicator (qwidget* Parent): Qwidget (parent), M_angle (0), M_timerid (-1), M_delay ( +), m_displayedwhenstopped (false), M_color (qt::black) {setsizepolicy (qsizepolicy::fixed, qsizepolicy::fixed); Setfocuspolicy (Qt::nofocus);}BOOLQprogressindicator::isanimated ()Const{return(M_timerid! =-1);}voidQprogressindicator::setdisplayedwhenstopped (BOOLState) {m_displayedwhenstopped = state; Update ();}BOOLQprogressindicator::isdisplayedwhenstopped ()Const{returnm_displayedwhenstopped;}voidQprogressindicator::startanimation () {m_angle =0;if(M_timerid = =-1) M_timerid = Starttimer (M_delay);}voidQprogressindicator::stopanimation () {if(M_timerid! =-1) KillTimer (M_timerid); M_timerid =-1; Update ();}voidQprogressindicator::setanimationdelay (intDelay) {if(M_timerid! =-1) KillTimer (M_timerid); M_delay = delay;if(M_timerid! =-1) M_timerid = Starttimer (M_delay);}voidQprogressindicator::setcolor (ConstQcolor & color) {m_color = color; Update ();} Qsize Qprogressindicator::sizehint ()Const{returnQsize ( -, -);}intQprogressindicator::heightforwidth (intWConst{returnW;}voidQprogressindicator::timerevent (Qtimerevent */*event*/) {M_angle = (m_angle+ -)% the; Update ();}voidQprogressindicator::p aintevent (Qpaintevent */*event*/){if(!m_displayedwhenstopped &&!isanimated ())return;intwidth = qmin ( This->width (), This->height ()); Qpainter P ( This); P.setrenderhint (qpainter::antialiasing);intOuterradius = (width-1)*0.5;intInnerradius = (width-1)*0.5*0.38;intCapsuleheight = Outerradius-innerradius;intCapsulewidth = (Width > +) ? Capsuleheight *. at: Capsuleheight *. the;intCapsuleradius = capsulewidth/2; for(intI=0; i< A; i++) {Qcolor color = M_color; Color.setalphaf (1.0f-(i/12.0f)); P.setpen (Qt::nopen); P.setbrush (color); P.save (); P.translate (Rect (). Center ()); P.rotate (m_angle-i*30.0f); P.drawroundedrect (-capsulewidth*0.5,-(Innerradius+capsuleheight), Capsulewidth, Capsuleheight, Capsuleradius, Capsuleradius); P.restore (); }}
Use
*=new QProgressIndicator(this);pIndicator->setColor(Qt::white);pIndicator->startAnimation();
Source code is not difficult, interested can be modified according to their own needs.
qt waiting Cue box (qprogressindicator)