Skip to content

Accordion

The accordion widget provides a container with multiple collapsible sections, where only one or multiple sections can be expanded at a time.

Preview

FXAccordion

Classes

FXAccordion

Bases: QWidget

A multi-section collapsible accordion widget.

Like FXCollapsibleWidget but for multiple mutually-exclusive sections (only one section open at a time by default).

Parameters:

Name Type Description Default

parent

Optional[QWidget]

Parent widget.

None

exclusive

bool

If True, only one section can be open at a time.

True

animation_duration

int

Duration of expand/collapse animation in ms.

150
Signals

section_expanded: Emitted when a section is expanded (section index). section_collapsed: Emitted when a section is collapsed (section index).

Examples:

>>> accordion = FXAccordion()
>>> accordion.add_section("General", general_content)
>>> accordion.add_section("Advanced", advanced_content)
>>> accordion.add_section("Settings", settings_content)

Methods:

Name Description
__iter__

Iterate over sections.

__len__

Return the number of sections.

add_section

Add a new section to the accordion.

collapse_all

Collapse all sections.

collapse_section

Collapse a section by index.

expand_all

Expand all sections (only works if not exclusive).

expand_section

Expand a section by index.

get_section

Get a section by index.

remove_section

Remove a section by index.

__iter__

__iter__()

Iterate over sections.

__len__

__len__() -> int

Return the number of sections.

add_section

add_section(
    title: str,
    content: Optional[Union[QWidget, QVBoxLayout]] = None,
    icon: Optional[str] = None,
) -> FXAccordionSection

Add a new section to the accordion.

Parameters:

Name Type Description Default

title

str

Section title.

required

content

Optional[Union[QWidget, QVBoxLayout]]

Content widget or layout.

None

icon

Optional[str]

Optional icon name for the header.

None

Returns:

Type Description
FXAccordionSection

The created FXAccordionSection.

collapse_all

collapse_all() -> None

Collapse all sections.

collapse_section

collapse_section(index: int) -> None

Collapse a section by index.

Parameters:

Name Type Description Default

index

int

The section index to collapse.

required

expand_all

expand_all() -> None

Expand all sections (only works if not exclusive).

expand_section

expand_section(index: int) -> None

Expand a section by index.

Parameters:

Name Type Description Default

index

int

The section index to expand.

required

get_section

get_section(index: int) -> Optional[FXAccordionSection]

Get a section by index.

Parameters:

Name Type Description Default

index

int

The section index.

required

Returns:

Type Description
Optional[FXAccordionSection]

The FXAccordionSection or None if index is invalid.

remove_section

remove_section(index: int) -> None

Remove a section by index.

Parameters:

Name Type Description Default

index

int

The section index to remove.

required

FXAccordionSection

Bases: FXThemeAware, QWidget

A single section of the accordion.

Parameters:

Name Type Description Default

parent

Optional[QWidget]

Parent widget.

None

title

str

Section title.

''

icon

Optional[str]

Optional icon name for the section header.

None

animation_duration

int

Duration of expand/collapse animation in ms.

150
Signals

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

Methods:

Name Description
collapse

Collapse the section.

expand

Expand the section.

set_content_layout

Set the content layout for this section.

set_content_widget

Set the content widget for this section.

toggle

Toggle the section state.

Attributes:

Name Type Description
is_expanded bool

Return whether the section is expanded.

title str

Return the section title.

is_expanded property

is_expanded: bool

Return whether the section is expanded.

title property

title: str

Return the section title.

collapse

collapse(animate: bool = True) -> None

Collapse the section.

Parameters:

Name Type Description Default

animate

bool

Whether to animate the collapse.

True

expand

expand(animate: bool = True) -> None

Expand the section.

Parameters:

Name Type Description Default

animate

bool

Whether to animate the expansion.

True

set_content_layout

set_content_layout(layout: QLayout) -> None

Set the content layout for this section.

Parameters:

Name Type Description Default

layout

QLayout

The layout to use for content.

required

set_content_widget

set_content_widget(widget: QWidget) -> None

Set the content widget for this section.

Parameters:

Name Type Description Default

widget

QWidget

The widget to display when expanded.

required

toggle

toggle() -> None

Toggle the section state.