ui_button

Path: /ui_components/ui_button.py

Overview

UIButton is a QPushButton subclass that provides a customizable, visually stylized button with configurable background color, dynamic text color for contrast, drop shadow effects, and smooth hover animations.

Purpose & Use Cases

Provide consistently styled buttons throughout the UI that automatically adjust text color for readability.

Implement interactive buttons with hover animations to enhance user experience and feedback.

Dependencies

PyQt5 (QPushButton, QGraphicsDropShadowEffect, Qt, QPropertyAnimation, QColor)

utilities/util_load_font.load_font from the Raven Development Team

Configuration & Parameters

Parameter Type Description Default
text string The label text displayed on the button.
color_rgb tuple(int, int, int) Background color of the button as an (R, G, B) triple.
parent QWidget Optional parent widget to embed this button in. None

Usage Example

submit_button = UIButton("Submit", (0, 122, 204), parent_window)

Behavior & Implementation

On initialization, the class loads the Chakra Petch font and sets up the base QPushButton. It calculates the luma of the provided background color to choose a contrasting text color (white or black). A QGraphicsDropShadowEffect is applied with configurable blur and alpha values, and QPropertyAnimation instances are configured to animate both the blur radius and shadow color on hover events. The enterEvent and leaveEvent methods trigger smooth transitions between base and hover states.

Error Handling

Errors during font loading or Qt initialization propagate through the application; this class does not catch exceptions explicitly. Invalid color values may raise errors from QColor.

Security Considerations

Ensure that color_rgb values are within the valid 0–255 range. The text parameter is directly placed in the UI; avoid untrusted input to prevent potential injection in rich text contexts.

Logging

This component does not perform any logging.

Testing & Validation

Unit tests should instantiate UIButton with various RGB values to verify correct text color selection and validate that hover animations execute without errors. Manual validation can be performed by adding the button to a QMainWindow and visually inspecting behavior.

Author

Author: Raven Development Team