35 : QWidget(parent), m_angle(0), m_timerId(-1), m_delay(40),
36 m_displayedWhenStopped(false), m_color(Qt::black) {
37 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
38 setFocusPolicy(Qt::NoFocus);
44 m_displayedWhenStopped = state;
50 return m_displayedWhenStopped;
57 m_timerId = startTimer(m_delay);
76 m_timerId = startTimer(m_delay);
102 m_angle = (m_angle + 30) % 360;
114 int width = qMin(this->width(), this->height());
117 p.setRenderHint(QPainter::Antialiasing);
119 auto outerRadius = int((width - 1) * 0.5);
120 auto innerRadius = int((width - 1) * 0.5 * 0.38);
122 int capsuleHeight = outerRadius - innerRadius;
124 (width > 32) ?
int(capsuleHeight * 0.23) : int(capsuleHeight * 0.35);
125 int capsuleRadius = capsuleWidth / 2;
127 for (
int i = 0; i < 12; ++i) {
128 QColor
color = m_color;
129 color.setAlphaF(
int(1.0f - (i / 12.0f)));
133 p.translate(rect().center());
134 p.rotate(
int(m_angle - i * 30.0f));
135 p.drawRoundedRect(
int(-capsuleWidth * 0.5), -(innerRadius + capsuleHeight),
136 capsuleWidth, capsuleHeight, capsuleRadius,
virtual void timerEvent(QTimerEvent *event)
QProgressIndicator::timerEvent do the actual animation.
void stopAnimation()
Stops the spin animation.
virtual void paintEvent(QPaintEvent *event)
QProgressIndicator::paintEvent draw the spinner.
bool isDisplayedWhenStopped() const
Returns a Boolean value indicating whether the receiver shows itself even when it is not animating.
void startAnimation()
Starts the spin animation.
void setColor(const QColor &color)
Sets the color of the components to the given color.
virtual QSize sizeHint() const
QProgressIndicator::sizeHint default minimum size.
bool isAnimated() const
Returns a Boolean value indicating whether the component is currently animated.
void setDisplayedWhenStopped(bool state)
Sets whether the component hides itself when it is not animating.
QProgressIndicator(QWidget *parent=0)
QProgressIndicator::QProgressIndicator constructor.
void setAnimationDelay(int delay)
Sets the delay between animation steps.
const QColor & color() const
Returns the color of the component.
int heightForWidth(int w) const
QProgressIndicator::heightForWidth square ratio.