Path: ui_components/ui_paragraph_text.py
UIParagraphText is a QLabel subclass that displays multi-line paragraph text with customizable font size, text color, padding, and alignment within a PyQt5 interface.
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.
PyQt5.QtWidgets.QLabel
utilities.util_load_font.load_font
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" |
paragraph = UIParagraphText(
text="Welcome to the Application.",
parent=main_window,
font_size=20,
color="#DDDDDD",
alignment="center"
)
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.
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.
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.
No internal logging is performed by this component.
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: Raven Development Team