ui_title_text

Path: /ui_components/ui_title_text.py

Overview

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.

Purpose & Use Cases

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.

Dependencies

PyQt5.QtWidgets.QLabel

utilities.util_load_font.load_font

Configuration & Parameters

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

Usage Example

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)
        

Behavior & Implementation

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.

Error Handling

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.

Security Considerations

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.

Logging

No internal logging is performed by UITitleText.

Testing & Validation

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

Author: Raven Development Team