QCustomArcLoader
Copyright 2021
by Parham Oyan and Oleg Frolov
Edits and improvements: Khamisi Kibet
QT GUI by: SPINN TV (YouTube)
License: GPL 3.0
Overview
QCustomArcLoader is a custom animated loader widget that displays a dynamic, spinning arc animation. Built on top of QFrame, it leverages the helper class ArcLoader to animate arc parameters (rotation, start angle, and span angle) using Qt's animation framework. This loader is ideal for indicating processing or loading states in Qt applications.

Key Features
-
Customizable Appearance:
Configure the loader’s color and pen width. -
Smooth, Coordinated Animations:
Uses sequential and parallel animations (viaQVariantAnimation,QSequentialAnimationGroup, andQParallelAnimationGroup) to animate rotation, span, and start angles. -
Dynamic Drawing:
Overrides thepaintEventto render arcs with anti-aliasing for smooth visuals. -
Reusable Components:
TheArcLoaderclass encapsulates the animation logic, making it easy to adjust or extend.
Classes
ArcLoader
A helper class that manages the arc’s animation parameters.
Constructor
ArcLoader(
parent=None,
spacer=0,
startAngle=270,
spanAngle=1/16,
direction=True,
duration=4000
)
- Parameters:
parent: The parent widget (typically aQCustomArcLoaderinstance).spacer: Initial offset for rotation.startAngle: Starting angle (in degrees) for the arc (default is 270°).spanAngle: The angular span of the arc (default is 1/16 of a full circle).direction: A boolean to control the animation sequence order.duration: Duration (in milliseconds) for the animations.
Methods
-
getRotationAnimation()
Returns aQVariantAnimationthat rotates the arc by updating thespacervalue from its current value to an additional two full rotations.
Animation updates are applied viaupdateSpacer. -
getSpanAngleAnimation()
Returns aQVariantAnimationthat animates thespanAnglefrom its default value to a value increased by 360°.
When finished, it callsanimationFinishedand updates viaupdateSpanAngle. -
getStartAngleAnimation()
Returns aQVariantAnimationthat animates thestartAnglefrom 270° to 630°.
Upon finishing,startAnimationFinishedresets angles and toggles the animation direction; updates are applied viaupdateStartAngle. -
startAnimations()
Combines the above animations into a sequential group (ordering depends on the currentdirection) and a parallel group that also runs the rotation animation. The animation group loops 10 times before stopping. -
Update Methods:
updateStartAngle(newValue): Updates the start angle and repaints the parent.updateSpacer(newValue): Updates the spacer value (rotation offset) and repaints.updateSpanAngle(newValue): Updates the span angle and repaints.
QCustomArcLoader
A custom loader widget that draws animated arcs using the parameters managed by an ArcLoader instance.
Constructor
QCustomArcLoader(
parent=None,
color=QColor("#ffffff"),
penWidth=20
)
- Parameters:
parent: The parent widget.color: Color of the arc(s) (default is white).penWidth: The width of the drawing pen.
Initialization
- Sets the frame shape to
NoFrameand fixes the widget size to 160×160 pixels. - Initializes the drawing pen via
initPen(). - Instantiates an
ArcLoaderwith preset parameters and starts its animations.
Methods
-
calculateXR(level)
Calculates the x-offset and remaining width/height (r) for drawing arcs based on a givenlevel(used for inner and outer arcs). -
draw()
Draws two arcs:- Primary Arc:
Uses the currentArcLoaderparameters to compute the span angle and draws the arc with a negative angle to achieve a clockwise effect. - Secondary Arc:
Draws a complementary arc (the remaining portion of the circle) with a thicker offset.
- Primary Arc:
-
initPen(penWidth)
Configures aQPenwith the specified color, width, and a rounded cap style. -
paintEvent(e)
Overrides the widget’s paint event to:- Set up a
QPainterwith anti-aliasing. - Set the pen.
- Call
draw()to render the arcs. - End the painter.
- Set up a
Usage Example
from qtpy.QtWidgets import QApplication
from qtpy.QtGui import QColor
from Custom_Widgets.LoadingIndicators import QCustomArcLoader
if __name__ == "__main__":
app = QApplication([])
# Create an instance of the arc loader with custom parameters
arcLoader = QCustomArcLoader(
color=QColor("#00AAFF"), # Custom arc color
penWidth=15 # Custom pen width
)
arcLoader.show()
app.exec_()
Notes
-
Animation Loop:
The animation is configured to loop 10 times. Modify the loop count instartAnimations()if you require continuous or different looping behavior. -
Customization:
Adjust parameters such ascolor,penWidth, anddurationto match your application's style. -
Integration:
This widget is part of the Custom_Widgets.LoadingIndicators module and can be integrated into any Qt application usingqtpy(compatible with PyQt and PySide).