ui_header_text

Path: /ui_components/ui_header_text.py

Overview

The UIHeaderText component displays a centered header text within a parent widget, maintaining a configurable top margin and automatically repositioning on parent resize.

Purpose & Use Cases

Display a prominent header or title at the top of an application window or overlay.

Maintain consistent positioning of header text when the window or parent widget is resized.

Dependencies

PyQt5.QtWidgets.QLabel

utilities.util_load_font.load_font

Configuration & Parameters

Parameter Type Description Default
text str The header text to display.
parent QWidget The parent widget in which the header is displayed. None
top_margin int Vertical offset in pixels from the top of the parent widget. 180
font_size int Size of the header font in points. 24
follow_parent_resize bool Whether to adjust position on parent resize events. True

Usage Example

python ui_header_text.py --text="Game Over" --top_margin=200 --font_size=28

Behavior & Implementation

On initialization, the component loads the custom font, applies the specified font_size and sets the text alignment and style. It calculates its geometry based on the top_margin and the width of the parent widget, then installs an event filter to listen for resize events (if follow_parent_resize is True). On each resize, it recalculates its position to remain centered at the specified margin.

Error Handling

No explicit error handling is implemented; if the parent is not provided or the font fails to load, the component silently returns without displaying.

Security Considerations

Inputs are limited to text and numeric parameters. Since text is displayed directly, avoid passing untrusted content that could lead to style injection.

Logging

This component does not produce log output.

Testing & Validation

Manually verify header positioning by resizing the application window and confirming the header remains correctly centered. Unit tests can instantiate the component with dummy parent widgets and assert geometry values on resize.

Author

Author: Raven Development Team