Path: /ui_components/ui_button.py
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.
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.
PyQt5 (QPushButton, QGraphicsDropShadowEffect, Qt, QPropertyAnimation, QColor)
utilities/util_load_font.load_font from the Raven Development Team
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 |
submit_button = UIButton("Submit", (0, 122, 204), parent_window)
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.
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.
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.
This component does not perform any logging.
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: Raven Development Team