ui_paragraph_text

Path: ui_components/ui_paragraph_text.py

Overview

UIParagraphText is a QLabel subclass that displays multi-line paragraph text with customizable font size, text color, padding, and alignment within a PyQt5 interface.

Purpose & Use Cases

Display descriptive or informational text blocks (e.g., instructions, tooltips, or application descriptions) in a user interface.

Render styled, wrapped text dynamically in dialogs, overlays, or content panels.

Dependencies

PyQt5.QtWidgets.QLabel

utilities.util_load_font.load_font

Configuration & Parameters

Parameter Type Description Default
text str The paragraph content to display. —
parent QWidget The parent widget in which this label is placed. None
font_size int Font size in pixels for the displayed text. 18
color str CSS color code for the text (e.g., "#FFFFFF" for white). "#FFFFFF"
alignment str or int Text alignment: "left", "center", "right", or any Qt alignment flag/constant. "left"

Usage Example

paragraph = UIParagraphText(
            text="Welcome to the Application.",
            parent=main_window,
            font_size=20,
            color="#DDDDDD",
            alignment="center"
        )
        

Behavior & Implementation

On initialization, the component loads a custom font via load_font, then constructs the QLabel with word wrapping enabled. It applies a stylesheet to set the font size, text color, and padding. The _parse_alignment helper method translates the provided alignment parameter into the appropriate Qt.Align flags, defaulting to left-top alignment if the input is invalid.

Error Handling

If the alignment parameter is not recognized (either not an int or an unrecognized string), _parse_alignment safely falls back to left-top alignment without raising an exception.

Security Considerations

Text content is displayed as plain text, preventing HTML injection. However, color and font size values are interpolated into the stylesheet—care should be taken if these values are sourced from untrusted input.

Logging

No internal logging is performed by this component.

Testing & Validation

Instantiate the component within a test QMainWindow or QWidget, supplying various font sizes, colors, and alignment values. Verify visually or via Qt test utilities that text wraps correctly, styles are applied, and invalid alignments default appropriately.

Author

Author: Raven Development Team