Skip to content

fxutils

Utils related to QT objects.

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
parent QWidget

Parent object.

required
shadow_object QWidget

Object to receive shadows.

required
color str

Color of the shadows. Defaults to #000000.

'#000000'
blur float

Blur level of the shadows. Defaults to 10.

10
offset float

Offset of the shadow from the shadow_object. Defaults to 0.

0

Returns:

Name Type Description
QGraphicsDropShadowEffect QGraphicsDropShadowEffect

The shadow object.

Examples:

>>> # Apply shadows to `self.top_toolbar` widget
>>> add_shadows(self, self.top_toolbar, "#212121")

convert_qicon_to_qpixmap

convert_qicon_to_qpixmap(
    icon: QIcon, desired_size: Optional[QSize] = None
) -> Optional[QPixmap]

Converts a QIcon to a QPixmap.

Parameters:

Name Type Description Default
icon QIcon

The QIcon to convert.

required
desired_size Optional[QSize]

The desired size for the pixmap (QSize). If None, the "best" available size will be used.

None

Returns:

Name Type Description
QPixmap Optional[QPixmap]

A QPixmap or None if no suitable pixmap is available.

Examples:

Let the size be decided

>>> icon = hou.qt.Icon("MISC_python")
>>> pixmap = convert_qicon_to_qpixmap(icon)

Choose a size

>>> icon = hou.qt.Icon("MISC_python")
>>> pixmap = convert_qicon_to_qpixmap(icon, QSize(48, 48))

create_action

create_action(
    parent: QWidget,
    name: str,
    icon: str,
    trigger: Callable,
    enable: bool = True,
    visible: bool = True,
    shortcut: str = None,
) -> Optional[QAction]

Creates a QACtion.

Parameters:

Name Type Description Default
parent QWidget

Parent object.

required
name str

Name to display.

required
icon str

Icon path.

required
trigger Callable

Function to trigger when clicked.

required
enable bool

Enable/disable. Defaults to True.

True
visible bool

Show/hide. Defaults to True.

True
shortcut str

If not None, key sequence (hotkeys) to use. Defaults to None.

None

Returns:

Type Description
Optional[QAction]

Optional[QAction]:

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.

Parameters:

Name Type Description Default
filter_bar_object QLineEdit

The QLineEdit widget representing the filter bar.

required
tree_to_filter QTreeWidget

The QTreeWidget to be filtered.

required
column int

The column index to use for text filtering. Defaults to 0.

0

Examples:

>>> filter_bar = QLineEdit()
>>> tree_widget = QTreeWidget()
>>> filter_tree(filter_bar, tree_widget, column=1)

load_ui

load_ui(parent: QWidget, ui_file: str) -> QWidget

Load a UI file and return the loaded UI as a QWidget.

Parameters:

Name Type Description Default
parent QWidget

Parent object.

required
ui_file 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

>>> from pathlib import Path
>>> ui_path = Path(__file__).with_suffix('.ui')
>>> loaded_ui = load_ui(self, ui_path)

set_formatted_tooltip

set_formatted_tooltip(
    widget: QWidget, title: str, tooltip: str, duration: int = 5
) -> None

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
widget QWidget

The widget to set the tooltip.

required
title str

The title of the tooltip.

required
tooltip str

The tooltip text.

required
duration int

The duration in seconds to show the tooltip. Defaults to 5.

5

Examples:

>>> set_formatted_tooltip(self, "Tooltip", "This is a <b>formatted</b> tooltip.")