Skip to content

collapsible

_collapsible

Collapsible widget implementation.

Classes:

Name Description
FXCollapsibleWidget

A widget that can expand or collapse its content.

Classes

FXCollapsibleWidget

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

Bases: FXThemeAware, QWidget


              flowchart TD
              fxgui.fxwidgets._collapsible.FXCollapsibleWidget[FXCollapsibleWidget]
              fxgui.fxstyle.FXThemeAware[FXThemeAware]

                              fxgui.fxstyle.FXThemeAware --> fxgui.fxwidgets._collapsible.FXCollapsibleWidget
                


              click fxgui.fxwidgets._collapsible.FXCollapsibleWidget href "" "fxgui.fxwidgets._collapsible.FXCollapsibleWidget"
              click fxgui.fxstyle.FXThemeAware href "" "fxgui.fxstyle.FXThemeAware"
            

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.

''
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
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
Signals

expanded: Emitted when the widget is expanded. collapsed: Emitted when the widget is collapsed.

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",
...     icon="settings"
... )

Initialize the collapsible section.

Methods:

Name Description
collapse

Collapse the widget to hide content.

expand

Expand the widget to show content.

get_icon

Get the current icon.

get_title

Get the current title text.

get_title_icon

Get the title icon (deprecated, use get_icon).

set_content_layout

Set the layout for the content area.

set_content_widget

Set the content widget directly.

set_icon

Set an icon to display before the title.

set_title

Set the title text.

set_title_icon

Set the title icon (deprecated, use set_icon).

toggle

Toggle the expanded/collapsed state.

Attributes:

Name Type Description
animation_duration int

Return the animation duration in milliseconds.

content_area QScrollArea

Return the content area (deprecated, use _content_area).

header_widget QFrame

Return the header widget (deprecated, use _header).

is_expanded bool

Return whether the widget is expanded.

max_content_height int

Return the maximum content height.

title str

Return the title text.

title_icon_label QLabel

Return the icon label (deprecated, use _icon_label).

title_label QLabel

Return the title label (deprecated, use _title_label).

toggle_button QToolButton

Return the toggle button (deprecated, use _toggle_btn).

Attributes
animation_duration property writable
animation_duration: int

Return the animation duration in milliseconds.

content_area property
content_area: QScrollArea

Return the content area (deprecated, use _content_area).

header_widget property
header_widget: QFrame

Return the header widget (deprecated, use _header).

is_expanded property
is_expanded: bool

Return whether the widget is expanded.

max_content_height property writable
max_content_height: int

Return the maximum content height.

title property
title: str

Return the title text.

title_icon_label property
title_icon_label: QLabel

Return the icon label (deprecated, use _icon_label).

title_label property
title_label: QLabel

Return the title label (deprecated, use _title_label).

toggle_button property
toggle_button: QToolButton

Return the toggle button (deprecated, use _toggle_btn).

Functions
collapse
collapse(animate: bool = True) -> None

Collapse the widget to hide content.

Parameters:

Name Type Description Default
animate bool

Whether to animate the collapse.

True
expand
expand(animate: bool = True) -> None

Expand the widget to show content.

Parameters:

Name Type Description Default
animate bool

Whether to animate the expansion.

True
get_icon
get_icon() -> Optional[QIcon]

Get the current icon.

Returns:

Type Description
Optional[QIcon]

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

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 title icon (deprecated, use get_icon).

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_content_widget
set_content_widget(widget: QWidget) -> None

Set the content widget directly.

Parameters:

Name Type Description Default
widget QWidget

The widget to display when expanded.

required
set_icon
set_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_icon("settings")  # Using icon name
>>> collapsible.set_icon(QIcon("path/to/icon.png"))  # Using QIcon
>>> collapsible.set_icon(None)  # Remove icon
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 the title icon (deprecated, use set_icon).

toggle
toggle() -> None

Toggle the expanded/collapsed state.