Path: /ui_components/ui_title_text.py
UITitleText is a QLabel subclass that displays centered, bold title text with a configurable top margin and font size, and automatically repositions itself when its parent widget is resized.
Display a prominent title at the top of a full-screen overlay or main window.
Provide a dynamic header that maintains its centered alignment on parent resize events.
PyQt5.QtWidgets.QLabel
utilities.util_load_font.load_font
Parameter | Type | Description | Default |
---|---|---|---|
text | string | The title text to display. | — |
parent | QWidget | The parent widget to attach the label to. | None |
top_margin | int | Vertical offset in pixels from the top of the parent. | 100 |
font_size | int | Point size for the title font. | 36 |
from ui_components.ui_title_text import UITitleText
# In your main window or overlay initialization:
title = UITitleText("Welcome to Raven Talon", parent=main_window, top_margin=120, font_size=48)
On initialization, UITitleText loads the custom Chakra Petch font, creates a bold QFont at the specified size, and sets white text color with centered alignment. It calculates its geometry based on the parent’s width and the given top margin, and installs an event filter on the parent to listen for QEvent.Resize events. When the parent is resized, it recalculates and updates its position to remain centered.
No explicit runtime errors are handled within UITitleText; it assumes a valid parent widget or None. If the font fails to load, load_font will raise or handle internally according to its own implementation.
Text passed to UITitleText is rendered verbatim; ensure that any dynamic text is sanitized if sourced from untrusted inputs to avoid injection of control characters.
No internal logging is performed by UITitleText.
Instantiate UITitleText in a test window, verify correct font rendering and top margin, then resize the window to ensure the title repositions and remains centered.
Author: Raven Development Team