Miscellaneous Widgets¶
Utility widgets: animated circular timer, drag-and-drop list, option selector, theme-aware icon, toggleable icon, modern toggle switch, animated notification banner, and collapsible accordion section.
CircularTimer¶
A QWidget that draws an animated arc representing elapsed time. The arc grows clockwise from the 12 o'clock position.
Signals:
| Signal | Signature | Emitted when |
|---|---|---|
timerReset |
() |
resetTimer() is called |
clicked |
() |
The widget is clicked |
cycleCompleted |
() |
One full cycle ends (whether or not loop is True) |
Constructor parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
parent |
QWidget \| None |
None |
Parent widget |
duration |
int |
5000 |
Total cycle duration in milliseconds |
ring_color |
QColor \| str |
"#0078d4" |
Color of the progress arc; supports hex, rgb(), rgba(), and named colors |
node_color |
QColor \| str |
"#2d2d2d" |
Fill color of the inner circle |
ring_width_mode |
"small" \| "medium" \| "large" |
"medium" |
Dynamic arc thickness preset |
pen_width |
int \| float \| None |
None |
Explicit arc thickness; takes priority over ring_width_mode if set |
loop |
bool |
False |
Whether the animation restarts automatically at the end of each cycle |
Properties:
| Property | Type | Description |
|---|---|---|
duration |
int |
Gets or sets the cycle duration in milliseconds |
elapsed |
int |
Gets or sets the elapsed time in milliseconds |
running |
bool |
Read-only; True while the timer is active |
ring_color |
QColor |
Gets or sets the arc color |
node_color |
QColor |
Gets or sets the inner circle color |
ring_width_mode |
str |
Gets or sets the thickness preset |
pen_width |
float \| None |
Gets or sets an explicit arc thickness |
loop |
bool |
Gets or sets whether the timer loops |
Methods:
| Method | Signature | Description |
|---|---|---|
startTimer() |
() -> None |
Starts the animation from the current elapsed position |
stopTimer() |
() -> None |
Stops the animation and resets elapsed to 0 |
resetTimer() |
() -> None |
Resets elapsed to 0 and emits timerReset without stopping |
refreshStyle() |
() -> None |
Re-applies the QSS stylesheet |
Example:
from PySide6.QtWidgets import QApplication
from ezqt_widgets import CircularTimer
app = QApplication([])
timer = CircularTimer(duration=10000, ring_color="#0078d4", loop=True)
timer.cycleCompleted.connect(lambda: print("cycle done"))
timer.clicked.connect(timer.resetTimer)
timer.startTimer()
timer.show()
app.exec()
CircularTimer
¶
CircularTimer(parent: WidgetParent = None, duration: int = 5000, ring_color: ColorType = '#0078d4', node_color: ColorType = '#2d2d2d', ring_width_mode: Literal['small', 'medium', 'large'] = 'medium', pen_width: int | float | None = None, loop: bool = False, *args: Any, **kwargs: Any)
Bases: QWidget
Animated circular timer for indicating progress or elapsed time.
Features
- Animated circular progress indicator
- Customizable colors for ring and center
- Configurable duration and loop mode
- Click events for interaction
- Smooth animation with configurable frame rate
| PARAMETER | DESCRIPTION |
|---|---|
parent
|
Parent widget (default: None).
TYPE:
|
duration
|
Total animation duration in milliseconds (default: 5000).
TYPE:
|
ring_color
|
Color of the progress arc (default: "#0078d4"). Supports: hex (#ff0000), rgb(255,0,0), rgba(255,0,0,0.5), names (red).
TYPE:
|
node_color
|
Color of the center (default: "#2d2d2d"). Supports: hex (#ffffff), rgb(255,255,255), rgba(255,255,255,0.8), names (white).
TYPE:
|
ring_width_mode
|
"small", "medium" (default), or "large". Controls the dynamic thickness of the arc.
TYPE:
|
pen_width
|
Thickness of the arc (takes priority over ring_width_mode if set).
TYPE:
|
loop
|
If True, the timer loops automatically at each cycle (default: False).
TYPE:
|
*args
|
Additional arguments passed to QWidget.
TYPE:
|
**kwargs
|
Additional keyword arguments passed to QWidget.
TYPE:
|
Signals
timerReset(): Emitted when the timer is reset. clicked(): Emitted when the widget is clicked. cycleCompleted(): Emitted at each end of cycle (even if loop=False).
Example
from ezqt_widgets import CircularTimer timer = CircularTimer(duration=10000, ring_color="#0078d4", loop=True) timer.cycleCompleted.connect(lambda: print("cycle done")) timer.clicked.connect(timer.reset) timer.start() timer.show()
Initialize the circular timer.
Source code in src/ezqt_widgets/widgets/misc/circular_timer.py
duration
property
writable
¶
Get the total duration.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The total duration in milliseconds. |
elapsed
property
writable
¶
Get the elapsed time.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The elapsed time in milliseconds. |
running
property
¶
Get whether the timer is running.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if running, False otherwise. |
ring_color
property
writable
¶
Get the ring color.
| RETURNS | DESCRIPTION |
|---|---|
QColor
|
The current ring color. |
node_color
property
writable
¶
Get the node color.
| RETURNS | DESCRIPTION |
|---|---|
QColor
|
The current node color. |
ring_width_mode
property
writable
¶
Get the ring width mode.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current ring width mode ("small", "medium", or "large"). |
pen_width
property
writable
¶
Get the pen width.
| RETURNS | DESCRIPTION |
|---|---|
float | None
|
The pen width, or None if using ring_width_mode. |
loop
property
writable
¶
Get whether the timer loops.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if looping, False otherwise. |
mousePressEvent
¶
Handle mouse press events.
| PARAMETER | DESCRIPTION |
|---|---|
_event
|
The mouse event (unused but required by signature).
TYPE:
|
startTimer
¶
Start the circular timer.
stopTimer
¶
resetTimer
¶
minimumSizeHint
¶
Get the recommended minimum size for the widget.
| RETURNS | DESCRIPTION |
|---|---|
QSize
|
The minimum size hint. |
paintEvent
¶
Draw the animated circular timer.
| PARAMETER | DESCRIPTION |
|---|---|
_event
|
The paint event (unused but required by signature).
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/circular_timer.py
refreshStyle
¶
Refresh the widget's style.
Useful after dynamic stylesheet changes.
DraggableItem¶
A QFrame representing a single item in a DraggableList. It embeds a HoverLabel whose hover icon triggers removal.
Signals:
| Signal | Signature | Emitted when |
|---|---|---|
itemClicked |
(str) |
The item is clicked; the string is item_id |
itemRemoved |
(str) |
The removal icon is clicked; the string is item_id |
Constructor parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
item_id |
str |
— | Unique identifier for this item (required) |
text |
str |
— | Text displayed in the item (required) |
parent |
QWidget \| None |
None |
Parent widget |
icon |
QIcon \| QPixmap \| str \| None |
None |
Icon for the HoverLabel; defaults to an icons8 drag icon |
compact |
bool |
False |
Compact display mode (reduced height: 24–32 px vs 40–60 px) |
Properties:
| Property | Type | Description |
|---|---|---|
icon_color |
str |
Gets or sets the icon color of the internal HoverLabel |
compact |
bool |
Gets or sets compact mode; adjusts height constraints |
Methods:
| Method | Signature | Description |
|---|---|---|
refreshStyle() |
() -> None |
Re-applies the QSS stylesheet |
Usage with DraggableList
DraggableItem is designed to be managed by DraggableList.
Use DraggableList.addItem() rather than instantiating DraggableItem directly in most cases.
DraggableItem
¶
DraggableItem(item_id: str, text: str, parent: WidgetParent = None, icon: IconSourceExtended = None, compact: bool = False, **kwargs: Any)
Bases: QFrame
Draggable item widget for DraggableList.
This item can be moved by drag & drop and always contains a HoverLabel for a consistent interface.
| PARAMETER | DESCRIPTION |
|---|---|
item_id
|
Unique identifier for the item.
TYPE:
|
text
|
Text to display in the item.
TYPE:
|
parent
|
Parent widget (default: None).
TYPE:
|
icon
|
Icon for the item (default: None, uses default icon).
TYPE:
|
compact
|
Whether to display in compact mode (default: False).
TYPE:
|
**kwargs
|
Additional keyword arguments passed to HoverLabel.
TYPE:
|
Signals
itemClicked(str): Emitted when the item is clicked. itemRemoved(str): Emitted when the item is removed.
Example
from ezqt_widgets import DraggableItem item = DraggableItem(item_id="item-1", text="First item") item.itemClicked.connect(lambda id: print(f"Clicked: {id}")) item.itemRemoved.connect(lambda id: print(f"Removed: {id}")) item.show()
Initialize the draggable item.
Source code in src/ezqt_widgets/widgets/misc/draggable_list.py
item_id
property
¶
Get the item identifier.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The unique identifier of the item. |
content_widget
property
¶
content_widget: HoverLabel
Get the inner HoverLabel widget.
| RETURNS | DESCRIPTION |
|---|---|
HoverLabel
|
The HoverLabel used for display and interaction. |
icon_color
property
writable
¶
Get the icon color of the HoverLabel.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current icon color. |
compact
property
writable
¶
Get the compact mode.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if compact mode is enabled, False otherwise. |
mousePressEvent
¶
Handle mouse press events for drag start.
| PARAMETER | DESCRIPTION |
|---|---|
event
|
The mouse event.
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/draggable_list.py
mouseMoveEvent
¶
Handle mouse movement for drag & drop.
| PARAMETER | DESCRIPTION |
|---|---|
event
|
The mouse event.
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/draggable_list.py
mouseReleaseEvent
¶
Handle mouse release events for drag end.
| PARAMETER | DESCRIPTION |
|---|---|
event
|
The mouse event.
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/draggable_list.py
sizeHint
¶
Get the recommended size for the widget based on content.
| RETURNS | DESCRIPTION |
|---|---|
QSize
|
The recommended size. |
Source code in src/ezqt_widgets/widgets/misc/draggable_list.py
minimumSizeHint
¶
Get the minimum size for the widget.
| RETURNS | DESCRIPTION |
|---|---|
QSize
|
The minimum size hint. |
Source code in src/ezqt_widgets/widgets/misc/draggable_list.py
refreshStyle
¶
Refresh the widget's style.
Useful after dynamic stylesheet changes.
DraggableList¶
A QWidget containing a scrollable list of DraggableItem instances that can be reordered by drag-and-drop and removed individually.
Signals:
| Signal | Signature | Emitted when |
|---|---|---|
itemMoved |
(str, int, int) |
An item is dropped at a new position; args are item_id, old_position, new_position |
itemRemoved |
(str, int) |
An item is removed; args are item_id, position |
itemAdded |
(str, int) |
An item is added; args are item_id, position |
itemClicked |
(str) |
An item is clicked; the string is item_id |
orderChanged |
(list) |
The item order changes; the list is the new ordered item_id list |
Constructor parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
parent |
QWidget \| None |
None |
Parent widget |
items |
list[str] \| None |
None |
Initial list of item identifiers |
allow_drag_drop |
bool |
True |
Whether drag-and-drop reordering is permitted |
allow_remove |
bool |
True |
Whether items can be removed via the hover icon |
max_height |
int |
300 |
Maximum widget height in pixels |
min_width |
int |
150 |
Minimum widget width in pixels |
compact |
bool |
False |
Compact display mode for all items |
Properties:
| Property | Type | Description |
|---|---|---|
items |
list[str] |
Gets or sets the full item list (returns a copy); setting rebuilds all item widgets |
item_count |
int |
Read-only; number of items currently in the list |
allow_drag_drop |
bool |
Gets or sets whether drag-and-drop is allowed |
allow_remove |
bool |
Gets or sets whether item removal is allowed; updates all existing items |
icon_color |
str |
Gets or sets the icon color for all items |
compact |
bool |
Gets or sets compact mode for all items |
min_width |
int |
Gets or sets the minimum widget width |
Methods:
| Method | Signature | Description |
|---|---|---|
addItem() |
(item_id: str, text: str \| None) -> None |
Adds an item; text defaults to item_id if None; no-op if item_id already exists |
removeItem() |
(item_id: str) -> bool |
Removes the item with the given id; returns True if found and removed |
clearItems() |
() -> None |
Removes all items and emits orderChanged([]) |
moveItem() |
(item_id: str, new_position: int) -> bool |
Moves an item to a new 0-based position; returns True on success |
getItemPosition() |
(item_id: str) -> int |
Returns the 0-based position of the item, or -1 if not found |
refreshStyle() |
() -> None |
Re-applies the QSS stylesheet |
Example:
from PySide6.QtWidgets import QApplication
from ezqt_widgets import DraggableList
app = QApplication([])
task_list = DraggableList(
items=["design", "implement", "test", "deploy"],
allow_drag_drop=True,
allow_remove=True,
compact=False,
)
task_list.itemMoved.connect(
lambda id, old, new: print(f"Moved '{id}' from {old} to {new}")
)
task_list.itemRemoved.connect(
lambda id, pos: print(f"Removed '{id}' at position {pos}")
)
task_list.show()
app.exec()
DraggableList
¶
DraggableList(parent: WidgetParent = None, items: list[str] | None = None, allow_drag_drop: bool = True, allow_remove: bool = True, max_height: int = 300, min_width: int = 150, compact: bool = False, *args: Any, **kwargs: Any)
Bases: QWidget
List widget with reorderable items via drag & drop and removal.
This widget allows managing a list of items that users can reorder by drag & drop and remove individually.
Features
- List of items reorderable by drag & drop
- Item removal via HoverLabel (red icon on hover)
- Consistent interface with HoverLabel for all items
- Signals for reordering and removal events
- Smooth and intuitive interface
- Appearance customization
- Automatic item order management
- Integrated removal icon in HoverLabel
Use cases
- Reorderable task list
- Option selector with customizable order
- File management interface
- Priority-ordered element configuration
| PARAMETER | DESCRIPTION |
|---|---|
parent
|
The parent widget (default: None).
TYPE:
|
items
|
Initial list of items (default: []).
TYPE:
|
allow_drag_drop
|
Allow drag & drop for reordering (default: True).
TYPE:
|
allow_remove
|
Allow item removal via HoverLabel (default: True).
TYPE:
|
max_height
|
Maximum height of the widget (default: 300).
TYPE:
|
min_width
|
Minimum width of the widget (default: 150).
TYPE:
|
compact
|
Display items in compact mode (reduced height) (default: False).
TYPE:
|
*args
|
Additional arguments passed to item widgets.
TYPE:
|
**kwargs
|
Additional keyword arguments passed to item widgets.
TYPE:
|
Signals
itemMoved(str, int, int): Emitted when an item is moved (item_id, old_position, new_position). itemRemoved(str, int): Emitted when an item is removed (item_id, position). itemAdded(str, int): Emitted when an item is added (item_id, position). itemClicked(str): Emitted when an item is clicked (item_id). orderChanged(list): Emitted when the item order changes (new ordered list).
Example
draggable_list = DraggableList( ... items=["Item 1", "Item 2", "Item 3"], ... icon="https://img.icons8.com/?size=100&id=8329&format=png&color=000000" ... ) draggable_list.itemMoved.connect( ... lambda item_id, old_pos, new_pos: print(f"Moved {item_id} from {old_pos} to {new_pos}") ... ) draggable_list.itemRemoved.connect( ... lambda item_id, pos: print(f"Removed {item_id} at {pos}") ... )
Initialize the draggable list.
Source code in src/ezqt_widgets/widgets/misc/draggable_list.py
items
property
writable
¶
Get the list of items.
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
A copy of the current items list. |
item_count
property
¶
Get the number of items in the list.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The number of items (read-only). |
allow_drag_drop
property
writable
¶
Get whether drag & drop is allowed.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if drag & drop is allowed, False otherwise. |
allow_remove
property
writable
¶
Get whether item removal is allowed.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if removal is allowed, False otherwise. |
icon_color
property
writable
¶
Get the icon color of the items.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current icon color. |
compact
property
writable
¶
Get the compact mode.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if compact mode is enabled, False otherwise. |
min_width
property
writable
¶
Get the minimum width of the widget.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The minimum width. |
addItem
¶
Add an item to the list.
| PARAMETER | DESCRIPTION |
|---|---|
item_id
|
Unique identifier for the item.
TYPE:
|
text
|
Text to display (uses item_id if None).
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/draggable_list.py
removeItem
¶
Remove an item from the list.
| PARAMETER | DESCRIPTION |
|---|---|
item_id
|
Identifier of the item to remove.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the item was removed, False otherwise. |
Source code in src/ezqt_widgets/widgets/misc/draggable_list.py
clearItems
¶
Remove all items from the list.
Source code in src/ezqt_widgets/widgets/misc/draggable_list.py
moveItem
¶
Move an item to a new position.
| PARAMETER | DESCRIPTION |
|---|---|
item_id
|
Identifier of the item to move.
TYPE:
|
new_position
|
New position (0-based).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the item was moved, False otherwise. |
Source code in src/ezqt_widgets/widgets/misc/draggable_list.py
getItemPosition
¶
Get the position of an item.
| PARAMETER | DESCRIPTION |
|---|---|
item_id
|
Identifier of the item.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Position of the item (-1 if not found). |
Source code in src/ezqt_widgets/widgets/misc/draggable_list.py
dragEnterEvent
¶
Handle drag enter events.
| PARAMETER | DESCRIPTION |
|---|---|
event
|
The drag enter event.
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/draggable_list.py
dragMoveEvent
¶
Handle drag move events.
| PARAMETER | DESCRIPTION |
|---|---|
event
|
The drag move event.
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/draggable_list.py
dropEvent
¶
Handle drop events.
| PARAMETER | DESCRIPTION |
|---|---|
event
|
The drop event.
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/draggable_list.py
sizeHint
¶
Get the recommended size for the widget based on content.
| RETURNS | DESCRIPTION |
|---|---|
QSize
|
The recommended size. |
Source code in src/ezqt_widgets/widgets/misc/draggable_list.py
minimumSizeHint
¶
Get the minimum size for the widget.
| RETURNS | DESCRIPTION |
|---|---|
QSize
|
The minimum size hint. |
Source code in src/ezqt_widgets/widgets/misc/draggable_list.py
refreshStyle
¶
Refresh the widget's style.
Useful after dynamic stylesheet changes.
OptionSelector¶
A QFrame displaying a horizontal or vertical row of text options with an animated selector rectangle that slides to the chosen option.
Signals:
| Signal | Signature | Emitted when |
|---|---|---|
clicked |
() |
Any option is clicked |
valueChanged |
(str) |
The selected option text changes |
valueIdChanged |
(int) |
The selected option index changes |
Constructor parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
items |
list[str] |
— | List of option texts to display (required) |
default_id |
int |
0 |
Index of the initially selected option |
min_width |
int \| None |
None |
Minimum width |
min_height |
int \| None |
None |
Minimum height |
orientation |
str |
"horizontal" |
Layout: "horizontal" or "vertical" |
animation_duration |
int |
300 |
Selector slide animation duration in milliseconds |
parent |
QWidget \| None |
None |
Parent widget |
Properties:
| Property | Type | Description |
|---|---|---|
value |
str |
Gets or sets the selected option by text |
value_id |
int |
Gets or sets the selected option by index |
options |
list[str] |
Read-only; returns a copy of the options list |
default_id |
int |
Gets or sets the default selection index |
selected_option |
FramedLabel \| None |
Read-only; the currently selected option widget |
orientation |
str |
Gets or sets the layout orientation |
min_width |
int \| None |
Gets or sets minimum width |
min_height |
int \| None |
Gets or sets minimum height |
animation_duration |
int |
Gets or sets the animation duration in milliseconds |
Methods:
| Method | Signature | Description |
|---|---|---|
initializeSelector() |
(default_id: int) -> None |
Positions the selector at the given index without animation |
addOption() |
(option_id: int, option_text: str) -> None |
Adds a new option at the given id position |
toggleSelection() |
(option_id: int) -> None |
Selects an option by id and animates the selector |
moveSelector() |
(option: FramedLabel) -> None |
Animates the selector to the given option widget |
refreshStyle() |
() -> None |
Re-applies the QSS stylesheet |
Example:
from PySide6.QtWidgets import QApplication
from ezqt_widgets import OptionSelector
app = QApplication([])
selector = OptionSelector(
items=["Day", "Week", "Month", "Year"],
default_id=0,
orientation="horizontal",
animation_duration=250,
)
selector.valueChanged.connect(lambda v: print(f"Selected: {v}"))
selector.show()
app.exec()
OptionSelector
¶
OptionSelector(items: list[str], default_id: int = 0, min_width: int | None = None, min_height: int | None = None, orientation: str = 'horizontal', animation_duration: int = 300, parent: WidgetParent = None, *args: Any, **kwargs: Any)
Bases: QFrame
Option selector widget with animated selector.
Features
- Multiple selectable options displayed as labels
- Animated selector that moves between options
- Single selection mode (radio behavior)
- Configurable default selection by ID (index)
- Smooth animations with easing curves
- Click events for option selection
- Uses IDs internally for robust value handling
| PARAMETER | DESCRIPTION |
|---|---|
items
|
List of option texts to display.
TYPE:
|
default_id
|
Default selected option ID (index) (default: 0).
TYPE:
|
min_width
|
Minimum width constraint for the widget (default: None).
TYPE:
|
min_height
|
Minimum height constraint for the widget (default: None).
TYPE:
|
orientation
|
Layout orientation: "horizontal" or "vertical" (default: "horizontal").
TYPE:
|
animation_duration
|
Duration of the selector animation in milliseconds (default: 300).
TYPE:
|
parent
|
The parent widget (default: None).
TYPE:
|
*args
|
Additional arguments passed to QFrame.
TYPE:
|
**kwargs
|
Additional keyword arguments passed to QFrame.
TYPE:
|
Signals
clicked(): Emitted when an option is clicked. valueChanged(str): Emitted when the selected value changes. valueIdChanged(int): Emitted when the selected value ID changes.
Example
from ezqt_widgets import OptionSelector selector = OptionSelector(items=["Day", "Week", "Month"], default_id=0) selector.valueChanged.connect(lambda v: print(f"Selected: {v}")) selector.show()
Initialize the option selector.
Source code in src/ezqt_widgets/widgets/misc/option_selector.py
value
property
writable
¶
Get or set the currently selected option text.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The currently selected option text, or empty string if none. |
value_id
property
writable
¶
Get or set the currently selected option ID.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The currently selected option ID. |
options
property
¶
Get the list of available options.
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
A copy of the options list. |
default_id
property
writable
¶
Get or set the default option ID.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The default option ID. |
selected_option
property
¶
selected_option: FramedLabel | None
Get the currently selected option widget.
| RETURNS | DESCRIPTION |
|---|---|
FramedLabel | None
|
The selected option widget, or None if none selected. |
orientation
property
writable
¶
Get or set the orientation of the selector.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current orientation ("horizontal" or "vertical"). |
min_width
property
writable
¶
Get or set the minimum width of the widget.
| RETURNS | DESCRIPTION |
|---|---|
int | None
|
The minimum width, or None if not set. |
min_height
property
writable
¶
Get or set the minimum height of the widget.
| RETURNS | DESCRIPTION |
|---|---|
int | None
|
The minimum height, or None if not set. |
animation_duration
property
writable
¶
Get or set the animation duration in milliseconds.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The animation duration in milliseconds. |
initializeSelector
¶
Initialize the selector with default position.
| PARAMETER | DESCRIPTION |
|---|---|
default_id
|
The default option ID to select.
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/option_selector.py
addOption
¶
Add a new option to the selector.
| PARAMETER | DESCRIPTION |
|---|---|
option_id
|
The ID for the option.
TYPE:
|
option_text
|
The text to display for the option.
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/option_selector.py
toggleSelection
¶
Handle option selection.
| PARAMETER | DESCRIPTION |
|---|---|
option_id
|
The ID of the option to select.
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/option_selector.py
moveSelector
¶
moveSelector(option: FramedLabel) -> None
Animate the selector to the selected option.
| PARAMETER | DESCRIPTION |
|---|---|
option
|
The option widget to move the selector to.
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/option_selector.py
sizeHint
¶
Get the recommended size for the widget.
| RETURNS | DESCRIPTION |
|---|---|
QSize
|
The recommended size. |
minimumSizeHint
¶
Get the minimum size hint for the widget.
| RETURNS | DESCRIPTION |
|---|---|
QSize
|
The minimum size hint. |
Source code in src/ezqt_widgets/widgets/misc/option_selector.py
refreshStyle
¶
Refresh the widget's style.
Useful after dynamic stylesheet changes.
ThemeIcon¶
A QIcon subclass that recolors itself to white (dark theme) or black (light theme) when the active theme changes. Custom colors for each theme can be specified.
Constructor parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
icon |
QIcon \| QPixmap \| str |
— | Source icon (required); None raises TypeError |
theme |
str |
"dark" |
Initial theme: "dark" or "light" |
dark_color |
QColor \| str \| None |
None |
Color applied in dark theme; defaults to white |
light_color |
QColor \| str \| None |
None |
Color applied in light theme; defaults to black |
Properties:
| Property | Type | Description |
|---|---|---|
theme |
str |
Gets or sets the active theme; setting recolors the icon immediately |
original_icon |
QIcon |
Gets or sets the source icon; setting triggers a recolor |
Methods:
| Method | Signature | Description |
|---|---|---|
setTheme() |
(theme: str) -> None |
Convenience alias for setting the theme property |
from_source() |
(source, theme, dark_color, light_color) -> ThemeIcon \| None |
Class method; returns None if source is None, otherwise wraps it in a ThemeIcon |
Example:
from ezqt_widgets import ThemeIcon
# Auto dark/light colors (white in dark mode, black in light mode)
icon = ThemeIcon("path/to/icon.png", theme="dark")
# Custom colors
icon = ThemeIcon(
"path/to/icon.svg",
dark_color="#FFFFFF",
light_color="#333333",
)
# Switch theme at runtime
icon.setTheme("light")
# Factory method — returns None if source is None
themed = ThemeIcon.from_source("path/to/icon.png", theme="dark")
ThemeIcon
¶
ThemeIcon(icon: IconSourceExtended, theme: str = 'dark', dark_color: QColor | str | None = None, light_color: QColor | str | None = None)
Bases: QIcon
QIcon subclass with automatic theme-based color adaptation.
The icon can be updated dynamically by calling :meth:setTheme
when the application theme changes.
| PARAMETER | DESCRIPTION |
|---|---|
icon
|
The source icon (
TYPE:
|
theme
|
The initial theme (
TYPE:
|
dark_color
|
Optional color for dark theme (hex or
TYPE:
|
light_color
|
Optional color for light theme (hex or
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
Properties
theme: Get or set the active theme. original_icon: Get or set the source icon.
Example
from ezqt_widgets.widgets.misc.theme_icon import ThemeIcon
Basic usage with automatic white/black color adaptation¶
icon = ThemeIcon("path/to/icon.png", theme="dark") button.setIcon(icon)
Custom colors for each theme¶
icon = ThemeIcon("icon.png", dark_color="#FFFFFF", light_color="#333333")
Factory method from any source (QIcon, QPixmap, path, or None)¶
themed = ThemeIcon.from_source("icon.svg", theme="light")
Adapt to a new theme dynamically¶
icon.setTheme("light")
Initialize the theme icon.
| PARAMETER | DESCRIPTION |
|---|---|
icon
|
The source icon (
TYPE:
|
theme
|
The initial theme (
TYPE:
|
dark_color
|
Optional color for dark theme (hex or
TYPE:
|
light_color
|
Optional color for light theme (hex or
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
Source code in src/ezqt_widgets/widgets/misc/theme_icon.py
theme
property
writable
¶
Get the current theme.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current theme ( |
original_icon
property
writable
¶
Get the original (uncolored) source icon.
| RETURNS | DESCRIPTION |
|---|---|
QIcon
|
The original icon. |
from_source
classmethod
¶
from_source(source: IconSourceExtended, theme: str = 'dark', dark_color: QColor | str | None = None, light_color: QColor | str | None = None) -> ThemeIcon | None
Create a ThemeIcon from any supported source.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The icon source (ThemeIcon, QIcon, QPixmap, or path string).
TYPE:
|
theme
|
The initial theme (
TYPE:
|
dark_color
|
Optional color for dark theme (hex or
TYPE:
|
light_color
|
Optional color for light theme (hex or
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ThemeIcon | None
|
A ThemeIcon instance or None if |
Source code in src/ezqt_widgets/widgets/misc/theme_icon.py
setTheme
¶
Update the icon color for the given theme.
Convenience method equivalent to setting the :attr:theme property.
| PARAMETER | DESCRIPTION |
|---|---|
theme
|
The new theme (
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/theme_icon.py
ToggleIcon¶
A QLabel that alternates between two icons representing an "opened" and a "closed" state. When no custom icons are provided, a built-in painted triangle arrow is used.
Signals:
| Signal | Signature | Emitted when |
|---|---|---|
stateChanged |
(str) |
The state changes; value is "opened" or "closed" |
clicked |
() |
The widget is clicked |
Constructor parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
parent |
QWidget \| None |
None |
Parent widget |
opened_icon |
QIcon \| QPixmap \| str \| None |
None |
Icon shown in the opened state; uses painted arrow if None |
closed_icon |
QIcon \| QPixmap \| str \| None |
None |
Icon shown in the closed state; uses painted arrow if None |
icon_size |
int |
16 |
Icon size in pixels (square) |
icon_color |
QColor \| str \| None |
None |
Color applied to icons; defaults to semi-transparent white |
initial_state |
str |
"closed" |
Starting state: "opened" or "closed" |
min_width |
int \| None |
None |
Minimum width |
min_height |
int \| None |
None |
Minimum height |
Properties:
| Property | Type | Description |
|---|---|---|
state |
str |
Gets or sets the current state ("opened" or "closed") |
opened_icon |
QPixmap \| None |
Gets or sets the opened-state icon |
closed_icon |
QPixmap \| None |
Gets or sets the closed-state icon |
icon_size |
int |
Gets or sets the icon size in pixels |
icon_color |
QColor |
Gets or sets the color applied to icons |
min_width |
int \| None |
Gets or sets minimum width |
min_height |
int \| None |
Gets or sets minimum height |
Methods:
| Method | Signature | Description |
|---|---|---|
toggleState() |
() -> None |
Switches between "opened" and "closed" |
setStateOpened() |
() -> None |
Forces state to "opened" |
setStateClosed() |
() -> None |
Forces state to "closed" |
isOpened() |
() -> bool |
Returns True if state is "opened" |
isClosed() |
() -> bool |
Returns True if state is "closed" |
refreshStyle() |
() -> None |
Re-applies the QSS stylesheet |
Keyboard support: Space, Enter, and Return keys toggle the state when the widget has focus.
Example:
from PySide6.QtWidgets import QApplication
from ezqt_widgets import ToggleIcon
app = QApplication([])
toggle = ToggleIcon(initial_state="closed", icon_size=20)
toggle.stateChanged.connect(lambda s: print(f"State: {s}"))
toggle.toggleState() # now "opened"
toggle.show()
app.exec()
ToggleIcon
¶
ToggleIcon(parent: WidgetParent = None, opened_icon: IconSourceExtended = None, closed_icon: IconSourceExtended = None, icon_size: int = 16, icon_color: ColorType | None = None, initial_state: str = 'closed', min_width: int | None = None, min_height: int | None = None, *args: Any, **kwargs: Any)
Bases: QLabel
Label with toggleable icons to indicate an open/closed state.
Features
- Toggleable icons for open/closed states
- Custom icons or default painted icons
- Configurable icon size and color
- Click and keyboard events for toggling
- Property-based state management
| PARAMETER | DESCRIPTION |
|---|---|
parent
|
Parent widget (default: None).
TYPE:
|
opened_icon
|
Icon to display when state is "opened" (ThemeIcon, QIcon, QPixmap, path, or URL). If None, uses paintEvent (default: None).
TYPE:
|
closed_icon
|
Icon to display when state is "closed" (ThemeIcon, QIcon, QPixmap, path, or URL). If None, uses paintEvent (default: None).
TYPE:
|
icon_size
|
Icon size in pixels (default: 16).
TYPE:
|
icon_color
|
Color to apply to icons (default: white with 0.5 opacity).
TYPE:
|
initial_state
|
Initial state ("opened" or "closed", default: "closed").
TYPE:
|
min_width
|
Minimum width of the widget (default: None).
TYPE:
|
min_height
|
Minimum height of the widget (default: None).
TYPE:
|
*args
|
Additional arguments passed to QLabel.
TYPE:
|
**kwargs
|
Additional keyword arguments passed to QLabel.
TYPE:
|
Signals
stateChanged(str): Emitted when the state changes ("opened" or "closed"). clicked(): Emitted when the widget is clicked.
Example
from ezqt_widgets import ToggleIcon toggle = ToggleIcon(initial_state="closed", icon_size=20) toggle.stateChanged.connect(lambda s: print(f"State: {s}")) toggle.toggleState() toggle.show()
Initialize the toggle icon.
Source code in src/ezqt_widgets/widgets/misc/toggle_icon.py
state
property
writable
¶
Get the current state.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current state ("opened" or "closed"). |
opened_icon
property
writable
¶
Get or set the opened state icon.
| RETURNS | DESCRIPTION |
|---|---|
QPixmap | None
|
The opened icon pixmap, or None if using default. |
closed_icon
property
writable
¶
Get or set the closed state icon.
| RETURNS | DESCRIPTION |
|---|---|
QPixmap | None
|
The closed icon pixmap, or None if using default. |
icon_size
property
writable
¶
Get or set the icon size.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The current icon size in pixels. |
icon_color
property
writable
¶
Get or set the icon color.
| RETURNS | DESCRIPTION |
|---|---|
QColor
|
The current icon color. |
min_width
property
writable
¶
Get or set the minimum width.
| RETURNS | DESCRIPTION |
|---|---|
int | None
|
The minimum width, or None if not set. |
min_height
property
writable
¶
Get or set the minimum height.
| RETURNS | DESCRIPTION |
|---|---|
int | None
|
The minimum height, or None if not set. |
mousePressEvent
¶
Handle mouse press events.
| PARAMETER | DESCRIPTION |
|---|---|
event
|
The mouse event.
TYPE:
|
keyPressEvent
¶
Handle key press events.
| PARAMETER | DESCRIPTION |
|---|---|
event
|
The key event.
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/toggle_icon.py
paintEvent
¶
Draw the icon if no custom icon is provided, centered in a square.
| PARAMETER | DESCRIPTION |
|---|---|
event
|
The paint event.
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/toggle_icon.py
minimumSizeHint
¶
Calculate a minimum square size based on icon and margins.
| RETURNS | DESCRIPTION |
|---|---|
QSize
|
The minimum size hint. |
Source code in src/ezqt_widgets/widgets/misc/toggle_icon.py
setTheme
¶
Update all icons' color for the given theme.
Can be connected directly to a theme-change signal to keep icons in sync with the application's color scheme.
| PARAMETER | DESCRIPTION |
|---|---|
theme
|
The new theme (
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/toggle_icon.py
toggleState
¶
setStateOpened
¶
setStateClosed
¶
isOpened
¶
Check if the state is opened.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if opened, False otherwise. |
isClosed
¶
Check if the state is closed.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if closed, False otherwise. |
refreshStyle
¶
Refresh the widget style.
Useful after dynamic stylesheet changes.
ToggleSwitch¶
A QWidget that renders an animated toggle switch with a sliding circle. Clicking or setting checked triggers a smooth animation.
Signals:
| Signal | Signature | Emitted when |
|---|---|---|
toggled |
(bool) |
The checked state changes; value is the new state |
Constructor parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
parent |
QWidget \| None |
None |
Parent widget |
checked |
bool |
False |
Initial checked state |
width |
int |
50 |
Width of the switch in pixels (minimum 20) |
height |
int |
24 |
Height of the switch in pixels (minimum 12) |
animation |
bool |
True |
Whether the circle slides with animation |
Properties:
| Property | Type | Description |
|---|---|---|
checked |
bool |
Gets or sets the toggle state; emits toggled and animates on change |
width |
int |
Gets or sets the switch width |
height |
int |
Gets or sets the switch height |
animation |
bool |
Gets or sets whether animation is enabled |
Methods:
| Method | Signature | Description |
|---|---|---|
toggle() |
() -> None |
Inverts the current checked state |
refreshStyle() |
() -> None |
Re-applies the QSS stylesheet |
Default colors (not configurable via constructor):
| Element | Off state | On state |
|---|---|---|
| Background | rgb(44, 49, 58) |
rgb(150, 205, 50) |
| Circle | rgb(255, 255, 255) |
rgb(255, 255, 255) |
| Border | rgb(52, 59, 72) |
rgb(52, 59, 72) |
Apply a QSS stylesheet to the parent or the application to override these colors.
Example:
from PySide6.QtWidgets import QApplication
from ezqt_widgets import ToggleSwitch
app = QApplication([])
switch = ToggleSwitch(checked=False, width=50, height=24, animation=True)
switch.toggled.connect(lambda on: print(f"On: {on}"))
switch.checked = True # animates to the on position
switch.show()
app.exec()
ToggleSwitch
¶
ToggleSwitch(parent: WidgetParent = None, checked: bool = False, width: int = 50, height: int = 24, animation: bool = True, *args: Any, **kwargs: Any)
Bases: QWidget
Modern toggle switch widget with animated sliding circle.
Features
- Smooth animation when toggling
- Customizable colors for on/off states
- Configurable size and border radius
- Click to toggle functionality
- Property-based access to state
- Signal emitted on state change
| PARAMETER | DESCRIPTION |
|---|---|
parent
|
The parent widget (default: None).
TYPE:
|
checked
|
Initial state of the toggle (default: False).
TYPE:
|
width
|
Width of the toggle switch (default: 50).
TYPE:
|
height
|
Height of the toggle switch (default: 24).
TYPE:
|
animation
|
Whether to animate the toggle (default: True).
TYPE:
|
*args
|
Additional arguments passed to QWidget.
TYPE:
|
**kwargs
|
Additional keyword arguments passed to QWidget.
TYPE:
|
Signals
toggled(bool): Emitted when the toggle state changes.
Example
from ezqt_widgets import ToggleSwitch switch = ToggleSwitch(checked=False, width=50, height=24) switch.toggled.connect(lambda state: print(f"On: {state}")) switch.checked = True switch.show()
Initialize the toggle switch.
Source code in src/ezqt_widgets/widgets/misc/toggle_switch.py
checked
property
writable
¶
Get the toggle state.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if checked, False otherwise. |
width
property
writable
¶
Get the width of the toggle.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The current width in pixels. |
height
property
writable
¶
Get the height of the toggle.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The current height in pixels. |
animation
property
writable
¶
Get whether animation is enabled.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if animation is enabled, False otherwise. |
toggle
¶
mousePressEvent
¶
Handle mouse press events.
| PARAMETER | DESCRIPTION |
|---|---|
event
|
The mouse event.
TYPE:
|
paintEvent
¶
Custom paint event to draw the toggle switch.
| PARAMETER | DESCRIPTION |
|---|---|
_event
|
The paint event (unused but required by signature).
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/toggle_switch.py
sizeHint
¶
Return the recommended size for the widget.
| RETURNS | DESCRIPTION |
|---|---|
QSize
|
The recommended size. |
minimumSizeHint
¶
Return the minimum size for the widget.
| RETURNS | DESCRIPTION |
|---|---|
QSize
|
The minimum size hint. |
refreshStyle
¶
Refresh the widget style.
Useful after dynamic stylesheet changes.
NotificationBanner¶
An animated slide-down notification banner QWidget that overlays the top of a parent widget. The banner can auto-dismiss after a configurable duration, and always provides a manual close button.
NotificationLevel¶
NotificationLevel is an Enum that sets the visual severity of the banner.
| Member | Value | Background color |
|---|---|---|
INFO |
"INFO" |
#3b82f6 (blue) |
WARNING |
"WARNING" |
#f59e0b (amber) |
ERROR |
"ERROR" |
#ef4444 (red) |
SUCCESS |
"SUCCESS" |
#22c55e (green) |
Signals:
| Signal | Signature | Emitted when |
|---|---|---|
dismissed |
() |
The banner is hidden, whether by auto-dismiss or manually |
Constructor parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
parent |
QWidget |
— | The parent widget that hosts the banner overlay (required, not None) |
Methods:
| Method | Signature | Description |
|---|---|---|
showNotification() |
(message: str, level: NotificationLevel, duration: int) -> None |
Displays the banner with the given message, level, and duration |
refreshStyle() |
() -> None |
Re-applies the QSS stylesheet |
showNotification() parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
message |
str |
— | Text displayed in the banner (required) |
level |
NotificationLevel |
NotificationLevel.INFO |
Severity level controlling background color and icon |
duration |
int |
3000 |
Display duration in milliseconds. Pass 0 for permanent (manual-only dismiss) |
Behavior notes:
- The banner is 48 px tall and spans the full width of the parent widget.
- Slide-in and slide-out use a
QPropertyAnimationon geometry with anOutCubiceasing curve (250 ms). - Calling
showNotification()while a banner is already visible cancels the previous auto-dismiss timer and replaces the content immediately. - The banner tracks parent resize events via an event filter and repositions itself automatically while visible.
- The
parentargument is mandatory. PassingNonewill raise anAttributeErrorat initialization.
Example:
from PySide6.QtWidgets import QApplication, QWidget
from ezqt_widgets import NotificationBanner, NotificationLevel
app = QApplication([])
window = QWidget()
window.resize(600, 400)
banner = NotificationBanner(parent=window)
banner.dismissed.connect(lambda: print("Banner dismissed"))
# Show a success banner that auto-dismisses after 4 seconds
banner.showNotification(
"Configuration saved successfully.",
NotificationLevel.SUCCESS,
duration=4000,
)
# Show a permanent error banner (requires manual close)
banner.showNotification(
"Connection lost. Check network settings.",
NotificationLevel.ERROR,
duration=0,
)
window.show()
app.exec()
NotificationBanner
¶
Bases: QWidget
Animated slide-down notification banner overlaying a parent widget.
The banner slides in from the top of its parent widget and can auto-dismiss after a configurable duration. A close button is always visible for manual dismissal. The banner repositions itself when the parent is resized via event filtering.
Features
- Slide-down animation via QPropertyAnimation on geometry
- Four severity levels: INFO, WARNING, ERROR, SUCCESS
- Auto-dismiss via QTimer when duration > 0
- Manual close button (×)
- Level icon via inline SVG rendered to ThemeIcon
- Parent resize tracking via event filter
| PARAMETER | DESCRIPTION |
|---|---|
parent
|
The parent widget inside which the banner is displayed. Must be a valid QWidget (not None).
TYPE:
|
Signals
dismissed(): Emitted when the banner is hidden (any cause).
Example
from ezqt_widgets import NotificationBanner, NotificationLevel banner = NotificationBanner(parent=main_widget) banner.dismissed.connect(lambda: print("Banner closed")) banner.showNotification("File saved!", NotificationLevel.SUCCESS)
Initialize the notification banner.
| PARAMETER | DESCRIPTION |
|---|---|
parent
|
The parent widget that hosts the banner overlay.
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/notification_banner.py
showNotification
¶
Display a notification banner with the given message and level.
| PARAMETER | DESCRIPTION |
|---|---|
message
|
The text to display in the banner.
TYPE:
|
level
|
The severity level (default: NotificationLevel.INFO).
TYPE:
|
duration
|
Display duration in milliseconds. Use 0 for a permanent banner that requires manual dismissal (default: 3000).
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/notification_banner.py
eventFilter
¶
Track parent resize events to reposition the banner.
| PARAMETER | DESCRIPTION |
|---|---|
obj
|
The object that generated the event.
TYPE:
|
event
|
The event.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
False to allow normal event propagation. |
Source code in src/ezqt_widgets/widgets/misc/notification_banner.py
refreshStyle
¶
Refresh the widget style.
Useful after dynamic stylesheet changes.
CollapsibleSection¶
An accordion-style QWidget with a clickable header and smooth expand/collapse animation. The header is always visible; clicking it toggles the content area between its natural height and zero.
Signals:
| Signal | Signature | Emitted when |
|---|---|---|
expandedChanged |
(bool) |
The expanded state changes; value is the new state |
Constructor parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
parent |
QWidget \| None |
None |
Parent widget |
title |
str |
"" |
Header title text |
expanded |
bool |
True |
Initial expanded state |
Properties:
| Property | Type | Description |
|---|---|---|
title |
str |
Gets or sets the header title text |
is_expanded |
bool |
Read-only; True if the content area is currently expanded |
Methods:
| Method | Signature | Description |
|---|---|---|
setContentWidget() |
(widget: QWidget) -> None |
Sets the widget displayed in the collapsible area; replaces any previous content |
expand() |
() -> None |
Expands the content area with animation; no-op if already expanded |
collapse() |
() -> None |
Collapses the content area with animation; no-op if already collapsed |
toggle() |
() -> None |
Toggles between expanded and collapsed states |
setTheme() |
(theme: str) -> None |
Updates the chevron icon color; connect to a themeChanged signal |
refreshStyle() |
() -> None |
Re-applies the QSS stylesheet |
Behavior notes:
- The expand/collapse animation operates on
maximumHeightof the content area usingQPropertyAnimationwith anInOutCubiceasing curve (200 ms). expandedChangedis emitted before the animation completes.- Calling
setContentWidget()replaces any previously set widget and re-applies the current expanded/collapsed state without animation. - The header chevron uses a
ToggleIconand reflects the current state (chevron-down when expanded, chevron-right when collapsed). setTheme()propagates the theme to the internalToggleIconchevron.
Example:
from PySide6.QtWidgets import QApplication, QWidget, QFormLayout, QLineEdit
from ezqt_widgets import CollapsibleSection
app = QApplication([])
# Build a form to use as content
form_widget = QWidget()
form_layout = QFormLayout(form_widget)
form_layout.addRow("Host:", QLineEdit("localhost"))
form_layout.addRow("Port:", QLineEdit("5432"))
section = CollapsibleSection(title="Database settings", expanded=False)
section.setContentWidget(form_widget)
section.expandedChanged.connect(lambda e: print(f"Expanded: {e}"))
section.show()
app.exec()
CollapsibleSection
¶
Bases: QWidget
Accordion-style section widget with animated expand/collapse.
The header is always visible. Clicking anywhere on the header (or calling toggle()) animates the content area between 0 height and its natural size hint height.
Features
- Clickable header with title label and ToggleIcon chevron
- Smooth height animation via QPropertyAnimation on maximumHeight
- Supports an arbitrary QWidget as content via setContentWidget()
- expand()/collapse()/toggle() public API
- Theme propagation to the ToggleIcon chevron
| PARAMETER | DESCRIPTION |
|---|---|
parent
|
The parent widget (default: None).
TYPE:
|
title
|
Header title text (default: "").
TYPE:
|
expanded
|
Initial expanded state (default: True).
TYPE:
|
Properties
title: Get or set the header title text. is_expanded: Get the current expanded state.
Signals
expandedChanged(bool): Emitted when the expanded state changes.
Example
from ezqt_widgets import CollapsibleSection section = CollapsibleSection(title="Settings", expanded=False) section.setContentWidget(my_form_widget) section.expandedChanged.connect(lambda e: print(f"Expanded: {e}")) section.show()
Initialize the collapsible section.
Source code in src/ezqt_widgets/widgets/misc/collapsible_section.py
title
property
writable
¶
Get the header title text.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The current title string. |
is_expanded
property
¶
Get the current expanded state.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the section is expanded, False if collapsed. |
setContentWidget
¶
Set the widget displayed in the collapsible content area.
Replaces any previously set content widget. The section keeps its current expanded/collapsed state.
| PARAMETER | DESCRIPTION |
|---|---|
widget
|
The widget to display as content.
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/collapsible_section.py
expand
¶
Expand the content area with animation.
Source code in src/ezqt_widgets/widgets/misc/collapsible_section.py
collapse
¶
Collapse the content area with animation.
Source code in src/ezqt_widgets/widgets/misc/collapsible_section.py
toggle
¶
setTheme
¶
Update the toggle icon color for the given theme.
Can be connected directly to a theme-change signal to keep the icon in sync with the application's color scheme.
| PARAMETER | DESCRIPTION |
|---|---|
theme
|
The new theme (
TYPE:
|
Source code in src/ezqt_widgets/widgets/misc/collapsible_section.py
refreshStyle
¶
Refresh the widget style.
Useful after dynamic stylesheet changes.