Path: /ui_components/ui_header_text.py
The UIHeaderText component displays a centered header text within a parent widget, maintaining a configurable top margin and automatically repositioning on parent resize.
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.
PyQt5.QtWidgets.QLabel
utilities.util_load_font.load_font
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 |
python ui_header_text.py --text="Game Over" --top_margin=200 --font_size=28
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.
No explicit error handling is implemented; if the parent is not provided or the font fails to load, the component silently returns without displaying.
Inputs are limited to text and numeric parameters. Since text is displayed directly, avoid passing untrusted content that could lead to style injection.
This component does not produce log output.
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: Raven Development Team