Qt 之 QProgressIndicator(等待提示框)
效果
由于录制程序的原因,引起gif效果不清晰,可忽略。
源码
QProgressIndicator.h
1 #ifndef QPROGRESSINDICATOR_H 2 #define QPROGRESSINDICATOR_H 3 4 #include <QWidget> 5 #include <QColor> 6 7 /*! 8 \class QProgressIndicator 9 \brief The QProgressIndicator class lets an application display a progress indicator to show that a lengthy task is under way. 10 11 Progress indicators are indeterminate and do nothing more than spin to show that the application is busy. 12 \sa QProgressBar 13 */ 14 class QProgressIndicator : public QWidget 15 28 29 /*! Returns a Boolean value indicating whether the cponent is currently animated. 30 \return Animation state. 31 \sa startAnimation stopAnimation 32 */ 33 bool isAnimated () const; 34 35 /*! Returns a Boolean value indicating whether the receiver shows itself even when it is not animating. 36 \return Return true if the progress indicator shows itself even when it is not animating. By default, it returns false. 37 \sa setDisplayedWhenStopped 38 */ 39 bool isDisplayedWhenStopped() const; 40 41 /*! Returns the color of the cponent. 42 \sa setColor 43 */ 44 const QColor & color() const 45 46 virtual QSize sizeHint() const; 47 int heightForWidth(int w) const; 48 public slots: 49 /*! Starts the spin animation. 50 \sa stopAnimation isAnimated 51 */ 52 void startAnimation(); 53 54 /*! Stops the spin animation. 55 \sa startAnimation isAnimated 56 */ 57 void stopAnimation(); 58 59 /*! Sets the delay between animation steps. 60 Setting the \a delay to a value larger than 40 slows the animation, while setting the \a delay to a smaller value speeds it up. 61 \param delay The delay, in milliseconds. 62 \sa animationDelay */ 64 void setAnimationDelay(int delay); 65 66 /*! Sets whether the cponent hides itself when it is not animating. 67 \param state The animation state. Set false to hide the progress indicator when it is not animating; otherwise true. 68 \sa isDisplayedWhenStopped 69 */ 70 void setDisplayedWhenStopped(bool state); 71 72 /*! Sets the color of the cponents to the given color. 73 \sa color 74 */ 75 void setColor(const QColor & color); 76 protected: 77 virtual void timerEvent(QTimerEvent * event); 78 virtual void paintEvent(QPaintEvent * event); 79 private: 80 int m_angle; 81 int m_timerId; 82 int m_delay; 83 bool m_displayedWhenStopped; 84 QColor m_color; 85 }; 86 87 #endif // QPROGRESSINDICATOR_HQProgressIndicatorpp
1 #include "QProgressIndicator.h" 2 3 #include <QPainter> 4 5 QProgressIndicator::QProgressIndicator(QWidget* parent) 6 : QWidget(parent), 7 m_angle(0), 8 m_timerId(1), 9 m_delay(40), 10 m_displayedWhenStopped(false), 11 m_color(Qt::black) 12 16 17 bool QProgressIndicator::isAnimated () const 18 21 22 void QProgressIndicator::setDisplayedWhenStopped(bool state) 23 28 29 bool QProgressIndicator::isDisplayedWhenStopped() const 30 33 34 void QProgressIndicator::startAnimation() 35 41 42 void QProgressIndicator::stopAnimation() 43 51 52 void QProgressIndicator::setAnimationDelay(int delay) 53 62 void QProgressIndicator::setColor(const QColor & color) 64 69 70 QSize QProgressIndicator::sizeHint() const 71 74 75 int QProgressIndicator::heightForWidth(int w) const 76 79 80 void QProgressIndicator::timerEvent(QTimerEvent * /*event*/) 81 86 87 void QProgressIndicator::paintEvent(QPaintEvent * /*event*/) 88 116 }使用
1 QProgressIndicator *pIndicator = new QProgressIndicator(this); 2 pIndicator>setColor(Qt::white); 3 pIndicator>startAnimation();源码没什么难度,有兴趣的可以根据需要自行修改。
上一篇:Qt 窗体淡入淡出
下一篇:Qt error: LNK1104: 无法打开文件xxxxx.exe报错解决方案
Qt
nsbtx文件怎么看,nsbtx文件用什么打开?
ess文件怎么看,ess文件用什么打开?
esproj文件怎么看,esproj文件用什么打开?
esps文件怎么看,esps文件用什么打开?
8st文件怎么看,8st文件用什么打开?
8med文件怎么看,8med文件用什么打开?
8li文件怎么看,8li文件用什么打开?
8cm文件怎么看,8cm文件用什么打开?
8bx文件怎么看,8bx文件用什么打开?
8by文件怎么看,8by文件用什么打开?