QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
QProgressIndicator Class Reference

Indeterminate progress indicator: twelve fading capsules that turn while the application is busy. More...

#include <qprogressindicator.h>

Inheritance diagram for QProgressIndicator:
Collaboration diagram for QProgressIndicator:

Public Slots

void startAnimation ()
 Start the spin animation from its first position.
void stopAnimation ()
 Stop the spin animation.
void setAnimationDelay (int delay)
 Set the delay between animation steps.
void setDisplayedWhenStopped (bool state)
 Set whether the indicator is drawn while it does not animate.
void setColor (const QColor &color)
 Set the colour the indicator is drawn in.

Public Member Functions

 QProgressIndicator (QWidget *parent=nullptr)
 Create a stopped indicator with a fixed size policy that never takes keyboard focus.
auto animationDelay () const -> int
 Delay between animation steps.
auto isAnimated () const -> bool
 Whether the indicator is animating.
auto isDisplayedWhenStopped () const -> bool
 Whether the indicator is drawn while it does not animate.
auto color () const -> const QColor &
 Colour set with setColor().
auto sizeHint () const -> QSize override
 Preferred size of the indicator.
auto heightForWidth (int w) const -> int override
 Keep the indicator square.

Protected Member Functions

void timerEvent (QTimerEvent *event) override
 Turn the indicator one step (30 degrees) and repaint.
void paintEvent (QPaintEvent *event) override
 Draw the twelve capsules, the newest opaque and the rest fading.

Private Attributes

int m_angle {0}
 Rotation of the first capsule, in degrees.
int m_timerId {-1}
 Id of the animation timer, or -1 while stopped.
int m_delay {40}
 Milliseconds between two animation steps.
bool m_displayedWhenStopped {false}
 Whether the indicator is drawn while it does not animate.
QColor m_color
 Colour from setColor(); invalid means the palette colour.

Detailed Description

Indeterminate progress indicator: twelve fading capsules that turn while the application is busy.

The widget is square. By default it draws nothing while it does not animate, but it stays shown and keeps its place in the layout. It draws in the palette's window text colour unless setColor() gave it a valid colour of its own, so it follows a light or dark theme.

Written by Morgan Leborgne (MIT licence) and maintained here since 2015.

Definition at line 27 of file qprogressindicator.h.

Constructor & Destructor Documentation

◆ QProgressIndicator()

QProgressIndicator::QProgressIndicator ( QWidget * parent = nullptr)
explicit

Create a stopped indicator with a fixed size policy that never takes keyboard focus.

Parameters
parentWidget the indicator is placed in.

Definition at line 11 of file qprogressindicator.cpp.

Member Function Documentation

◆ animationDelay()

auto QProgressIndicator::animationDelay ( ) const -> int
inlinenodiscard

Delay between animation steps.

Returns
Milliseconds between two steps; 40 by default.
See also
setAnimationDelay

Definition at line 43 of file qprogressindicator.h.

◆ color()

auto QProgressIndicator::color ( ) const -> const QColor &
inlinenodiscard

Colour set with setColor().

Returns
The colour; invalid while the palette colour is in use.
See also
setColor

Definition at line 64 of file qprogressindicator.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ heightForWidth()

auto QProgressIndicator::heightForWidth ( int w) const -> int
nodiscardoverride

Keep the indicator square.

Parameters
wWidth on offer.
Returns
The same value as the height.

Definition at line 66 of file qprogressindicator.cpp.

◆ isAnimated()

auto QProgressIndicator::isAnimated ( ) const -> bool
nodiscard

Whether the indicator is animating.

Returns
true while the animation timer runs.
See also
startAnimation stopAnimation

Definition at line 16 of file qprogressindicator.cpp.

Here is the caller graph for this function:

◆ isDisplayedWhenStopped()

auto QProgressIndicator::isDisplayedWhenStopped ( ) const -> bool
nodiscard

Whether the indicator is drawn while it does not animate.

Returns
true if it is drawn when stopped; false by default.
See also
setDisplayedWhenStopped

Definition at line 24 of file qprogressindicator.cpp.

◆ paintEvent()

void QProgressIndicator::paintEvent ( QPaintEvent * event)
overrideprotected

Draw the twelve capsules, the newest opaque and the rest fading.

Parameters
eventPaint event; not used.

Definition at line 74 of file qprogressindicator.cpp.

Here is the call graph for this function:

◆ setAnimationDelay

void QProgressIndicator::setAnimationDelay ( int delay)
slot

Set the delay between animation steps.

A value above 40 slows the animation, a smaller one speeds it up. A running animation goes on with the new delay.

Parameters
delayDelay in milliseconds.
See also
animationDelay

Definition at line 46 of file qprogressindicator.cpp.

◆ setColor

void QProgressIndicator::setColor ( const QColor & color)
slot

Set the colour the indicator is drawn in.

Parameters
colorThe colour to use. An invalid QColor goes back to the palette's window text colour.
See also
color

Definition at line 58 of file qprogressindicator.cpp.

Here is the call graph for this function:

◆ setDisplayedWhenStopped

void QProgressIndicator::setDisplayedWhenStopped ( bool state)
slot

Set whether the indicator is drawn while it does not animate.

Parameters
statetrue to draw it when stopped, false to draw nothing then.
See also
isDisplayedWhenStopped

Definition at line 18 of file qprogressindicator.cpp.

◆ sizeHint()

auto QProgressIndicator::sizeHint ( ) const -> QSize
nodiscardoverride

Preferred size of the indicator.

Returns
20 by 20 pixels.

Definition at line 64 of file qprogressindicator.cpp.

◆ startAnimation

void QProgressIndicator::startAnimation ( )
slot

Start the spin animation from its first position.

See also
stopAnimation isAnimated

Definition at line 28 of file qprogressindicator.cpp.

◆ stopAnimation

void QProgressIndicator::stopAnimation ( )
slot

Stop the spin animation.

See also
startAnimation isAnimated

Definition at line 36 of file qprogressindicator.cpp.

◆ timerEvent()

void QProgressIndicator::timerEvent ( QTimerEvent * event)
overrideprotected

Turn the indicator one step (30 degrees) and repaint.

Parameters
eventTimer event; not used.

Definition at line 68 of file qprogressindicator.cpp.

Member Data Documentation

◆ m_angle

int QProgressIndicator::m_angle {0}
private

Rotation of the first capsule, in degrees.

Definition at line 133 of file qprogressindicator.h.

◆ m_color

QColor QProgressIndicator::m_color
private

Colour from setColor(); invalid means the palette colour.

Definition at line 141 of file qprogressindicator.h.

◆ m_delay

int QProgressIndicator::m_delay {40}
private

Milliseconds between two animation steps.

Definition at line 137 of file qprogressindicator.h.

◆ m_displayedWhenStopped

bool QProgressIndicator::m_displayedWhenStopped {false}
private

Whether the indicator is drawn while it does not animate.

Definition at line 139 of file qprogressindicator.h.

◆ m_timerId

int QProgressIndicator::m_timerId {-1}
private

Id of the animation timer, or -1 while stopped.

Definition at line 135 of file qprogressindicator.h.


The documentation for this class was generated from the following files: