fxutils
fxutils
¶
Utility functions for the fxgui package.
This module provides general-purpose utility functions for Qt-based applications including UI loading, action creation, widget effects, tree filtering, and tooltip formatting.
Functions:
| Name | Description |
|---|---|
load_ui |
Load a Qt Designer UI file. |
create_action |
Create a QAction with common settings. |
add_shadows |
Apply drop shadow effect to a widget. |
filter_tree |
Filter QTreeWidget items by text. |
set_formatted_tooltip |
Set a styled tooltip with title. |
get_formatted_time |
Get current time as formatted string. |
deprecated |
Decorator to mark functions as deprecated. |
Examples:
Loading a UI file:
Creating an action:
>>> action = create_action(
... parent=window,
... name="Save",
... icon=get_icon("save"),
... trigger=save_callback,
... shortcut="Ctrl+S"
... )
Functions¶
add_shadows
¶
add_shadows(
parent: QWidget,
shadow_object: QWidget,
color: str = "#000000",
blur: float = 10,
offset: float = 0,
) -> QGraphicsDropShadowEffect
Apply shadows to a widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
QWidget
|
Parent object. |
required |
|
QWidget
|
Object to receive shadows. |
required |
|
str
|
Color of the shadows. Defaults to |
'#000000'
|
|
float
|
Blur level of the shadows. Defaults to |
10
|
|
float
|
Offset of the shadow from the
|
0
|
Returns:
| Name | Type | Description |
|---|---|---|
QGraphicsDropShadowEffect |
QGraphicsDropShadowEffect
|
The shadow object. |
Examples:
create_action
¶
create_action(
parent: QWidget,
name: str,
icon: Union[str, QIcon] = None,
trigger: Optional[Callable] = None,
enable: bool = True,
visible: bool = True,
shortcut: Optional[str] = None,
checkable: bool = False,
icon_name: Optional[str] = None,
) -> QAction
Create a QAction with common settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
QWidget
|
Parent widget for the action. |
required |
|
str
|
Display name for the action. |
required |
|
Union[str, QIcon]
|
Icon for the action. Can be a path string or a QIcon object.
Deprecated: prefer using |
None
|
|
Optional[Callable]
|
Callback function to execute when triggered. Defaults to None. |
None
|
|
bool
|
Whether the action is enabled. Defaults to True. |
True
|
|
bool
|
Whether the action is visible. Defaults to True. |
True
|
|
Optional[str]
|
Keyboard shortcut (e.g., "Ctrl+S"). Defaults to None. |
None
|
|
bool
|
Whether the action is checkable. Defaults to False. |
False
|
|
Optional[str]
|
Name of the icon from fxicons. When provided, the action will be registered for automatic icon updates on theme changes. |
None
|
Returns:
| Type | Description |
|---|---|
QAction
|
The created QAction. |
Examples:
deprecated
¶
Decorator to mark functions as deprecated.
When a decorated function is called, it emits a DeprecationWarning to alert users that the function will be removed in a future version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Callable
|
The function to mark as deprecated. |
required |
Returns:
| Type | Description |
|---|---|
Callable
|
A wrapper function that emits a warning before calling the original. |
Examples:
filter_tree
¶
filter_tree(
filter_bar_object: QLineEdit, tree_to_filter: QTreeWidget, column: int = 0
) -> None
Filters the items of a tree by displaying or hiding them based on whether they match the filter text. Both root and child items are considered.
.. deprecated::
Consider using :class:fxgui.fxcore.FXSortFilterProxyModel for
more sophisticated filtering with fuzzy matching support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
QLineEdit
|
The QLineEdit widget representing the filter bar. |
required |
|
QTreeWidget
|
The QTreeWidget to be filtered. |
required |
|
int
|
The column index to use for text filtering.
Defaults to |
0
|
Examples:
get_formatted_time
¶
get_formatted_time(
display_seconds: bool = False, display_date: bool = False
) -> str
Returns the current time as a formatted string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to display the seconds.
Defaults to |
False
|
|
bool
|
Whether to display the date.
Defaults to |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The formatted current time. |
Examples:
load_ui
¶
Load a UI file and return the loaded UI as a QWidget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
QWidget
|
Parent object. |
required |
|
str
|
Path to the UI file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
QWidget |
QWidget
|
The loaded UI. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the specified UI file doesn't exist. |
Examples:
To load a UI file located in the same directory as the Python script
set_formatted_tooltip
¶
Set a formatted tooltip. The tooltip will be displayed with a bold title, and a separator line between the title and the tooltip text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
QWidget
|
The widget to set the tooltip. |
required |
|
str
|
The title of the tooltip. |
required |
|
str
|
The tooltip text. |
required |
|
int
|
The duration in seconds to show the tooltip.
Defaults to |
5
|
Examples: