Skip to content

QCollapsible

A QFrame with a header button that hides or shows its contents, with an animation. Add contents with addWidget.

  • expand() and collapse() open and close it from code (pass animate=False to skip the animation), and toggled emits True or False when it opens or closes.
  • setExpandedIcon and setCollapsedIcon change the header's icons (a QIcon, or a string such as "▼"), and setDuration and setEasingCurve change the animation.
  • setLocked(True) keeps it from opening or closing, until it's unlocked.
QCollapsible QCollapsible
from qtpy.QtWidgets import QApplication, QLabel, QPushButton

from superqt import QCollapsible

app = QApplication([])

collapsible = QCollapsible("Advanced analysis")
collapsible.addWidget(QLabel("This is the inside of the collapsible frame"))
for i in range(4):
    collapsible.addWidget(QPushButton(f"Content button {i + 1}"))

collapsible.expand(animate=False)
collapsible.show()
app.exec()

QCollapsible

QCollapsible(
    title: str = "",
    parent: QWidget | None = None,
    expandedIcon: QIcon | str | None = "▼",
    collapsedIcon: QIcon | str | None = "▲",
)

A collapsible widget to hide and unhide child widgets.

A signal is emitted when the widget is expanded (True) or collapsed (False).

Based on https://stackoverflow.com/a/68141638

Subclass of QFrame

QCollapsible inherits all of QFrame's methods, signals, and properties. Only those that superqt adds or changes are listed here.

Signals

  • toggled(bool)

Methods

A collapsible widget to hide and unhide child widgets.

A signal is emitted when the widget is expanded (True) or collapsed (False).

Based on https://stackoverflow.com/a/68141638

addWidget

addWidget(widget: QWidget) -> None

Add a widget to the central content widget's layout.

collapse

collapse(animate: bool = True) -> None

Collapse (hide) the collapsible section.

collapsedIcon

collapsedIcon() -> QIcon

Returns the icon used when the widget is collapsed.

content

content() -> QWidget

Return the current content widget.

expand

expand(animate: bool = True) -> None

Expand (show) the collapsible section.

expandedIcon

expandedIcon() -> QIcon

Returns the icon used when the widget is expanded.

isExpanded

isExpanded() -> bool

Return whether the collapsible section is visible.

locked

locked() -> bool

Return True if collapse/expand is disabled.

removeWidget

removeWidget(widget: QWidget) -> None

Remove widget from the central content widget's layout.

setCollapsedIcon

setCollapsedIcon(icon: QIcon | str | None = None) -> None

Set the icon on the toggle button when the widget is collapsed.

setContent

setContent(content: QWidget) -> None

Replace central widget (the widget that gets expanded/collapsed).

setDuration

setDuration(msecs: int) -> None

Set duration of the collapse/expand animation.

setEasingCurve

setEasingCurve(easing: QEasingCurve | Type) -> None

Set the easing curve for the collapse/expand animation.

setExpandedIcon

setExpandedIcon(icon: QIcon | str | None = None) -> None

Set the icon on the toggle button when the widget is expanded.

setLocked

setLocked(locked: bool = True) -> None

Set whether collapse/expand is disabled.

setText

setText(text: str) -> None

Set the text of the toggle button.

text

text() -> str

Return the text of the toggle button.

toggleButton

toggleButton() -> QPushButton

Return the toggle button.