Skip to content

Collapsible Widget

The collapsible widget provides a single expandable/collapsible section with a header and content area.

Preview

FXCollapsibleWidget

FXCollapsibleWidget

Bases: FXThemeAware, QWidget

A widget that can expand or collapse its content.

The widget consists of a header with a toggle button and a content area that can be shown or hidden with an animation effect.

Parameters:

Name Type Description Default

parent

Optional[QWidget]

Parent widget.

None

title

str

Title displayed in the header.

''

animation_duration

int

Duration of expand/collapse animation in ms.

150

max_content_height

int

Maximum height for content area when expanded (0 = no limit).

300

title_icon

Optional[Union[QIcon, str]]

Optional icon to display before the title. Can be a QIcon, an icon name string (for fxicons), or None.

None

Examples:

>>> from qtpy.QtWidgets import QLabel, QVBoxLayout
>>> collapsible = FXCollapsibleWidget(title="Settings")
>>> layout = QVBoxLayout()
>>> layout.addWidget(QLabel("Option 1"))
>>> layout.addWidget(QLabel("Option 2"))
>>> collapsible.set_content_layout(layout)
>>>
>>> # With an icon
>>> collapsible_with_icon = FXCollapsibleWidget(
...     title="Settings",
...     title_icon="settings"
... )

Methods:

Name Description
__init__

Initialize the collapsible section.

get_title

Get the current title text.

get_title_icon

Get the current title icon.

set_content_layout

Set the layout for the content area.

set_title

Set the title text.

set_title_icon

Set an icon to display before the title.

__init__

__init__(
    parent: Optional[QWidget] = None,
    title: str = "",
    animation_duration: int = 150,
    max_content_height: int = 300,
    title_icon: Optional[Union[QIcon, str]] = None,
)

Initialize the collapsible section.

get_title

get_title() -> str

Get the current title text.

Returns:

Type Description
str

The current title text.

get_title_icon

get_title_icon() -> Optional[QIcon]

Get the current title icon.

Returns:

Type Description
Optional[QIcon]

The current title icon, or None if no icon is set.

set_content_layout

set_content_layout(content_layout: QLayout) -> None

Set the layout for the content area.

Parameters:

Name Type Description Default

content_layout

QLayout

The layout to set for the content area.

required

set_title

set_title(title: str) -> None

Set the title text.

Parameters:

Name Type Description Default

title

str

The title text to display.

required

set_title_icon

set_title_icon(icon: Union[QIcon, str, None]) -> None

Set an icon to display before the title.

Parameters:

Name Type Description Default

icon

Union[QIcon, str, None]

The icon to display. Can be: - A QIcon instance - A string icon name (resolved via fxicons.get_icon) - None to remove the icon

required

Examples:

>>> collapsible = FXCollapsibleWidget(title="Settings")
>>> collapsible.set_title_icon("settings")  # Using icon name
>>> collapsible.set_title_icon(QIcon("path/to/icon.png"))  # Using QIcon
>>> collapsible.set_title_icon(None)  # Remove icon