drop_zone
_drop_zone
¶
Drag and drop zone widget for file and folder selection.
Classes:
| Name | Description |
|---|---|
FXDropZone |
A drag and drop zone widget for file and folder selection. |
Functions:
| Name | Description |
|---|---|
example |
Demonstrate the FXDropZone widget. |
Classes¶
FXDropZone
¶
FXDropZone(
parent: Optional[QWidget] = None,
title: str = "Drag and Drop Files Here",
description: str = "or use the Browse Files... button below",
accept_mode: str = "files",
extensions: Optional[Set[str]] = None,
multiple: bool = True,
icon_name: str = "upload_file",
show_formats: bool = True,
show_buttons: bool = True,
show_tree: bool = True,
)
Bases: FXThemeAware, QWidget
flowchart TD
fxgui.fxwidgets._drop_zone.FXDropZone[FXDropZone]
fxgui.fxstyle.FXThemeAware[FXThemeAware]
fxgui.fxstyle.FXThemeAware --> fxgui.fxwidgets._drop_zone.FXDropZone
click fxgui.fxwidgets._drop_zone.FXDropZone href "" "fxgui.fxwidgets._drop_zone.FXDropZone"
click fxgui.fxstyle.FXThemeAware href "" "fxgui.fxstyle.FXThemeAware"
A drag and drop zone widget for file and folder selection.
This widget provides a visual drop target for files and folders with: - Drag and drop support with visual feedback - Optional browse and clear buttons (external to drop area) - Customizable accepted extensions with display - Support for files, folders, or both - Visual states: default, hover, drag-active - Built-in tree view that appears after files are dropped - Tree view also accepts drag & drop for additional files - Context menu for removing individual files
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Optional[QWidget]
|
Parent widget. |
None
|
|
str
|
Main title text displayed in the drop zone. |
'Drag and Drop Files Here'
|
|
str
|
Description text displayed below the title. |
'or use the Browse Files... button below'
|
|
str
|
What to accept - 'files', 'folders', or 'both'. |
'files'
|
|
Optional[Set[str]]
|
Set of allowed file extensions (e.g., {'.png', '.jpg'}). If None, all extensions are accepted. |
None
|
|
bool
|
Whether to allow multiple file/folder selection. |
True
|
|
str
|
Icon name to display (default: 'upload_file'). |
'upload_file'
|
|
bool
|
Whether to display accepted formats below title. |
True
|
|
bool
|
Whether to show Browse/Clear buttons. |
True
|
|
bool
|
Whether to show file tree after files are dropped. |
True
|
Signals
files_dropped: Emitted when files/folders are dropped or selected. Passes a list of Path objects. files_cleared: Emitted when files are cleared. file_removed: Emitted when a single file is removed from the tree. Passes the Path that was removed. drag_entered: Emitted when a valid drag enters the drop zone. drag_left: Emitted when a drag leaves the drop zone.
Examples:
>>> # Accept image files only with tree view
>>> drop_zone = FXDropZone(
... title="Drop Images Here",
... description="or use the Browse Files... button below",
... extensions={'.png', '.jpg', '.exr'},
... show_tree=True
... )
>>> drop_zone.files_dropped.connect(lambda paths: print(paths))
>>>
>>> # Accept folders only (no tree)
>>> folder_zone = FXDropZone(
... title="Drop Project Folder",
... accept_mode='folders',
... show_tree=False
... )
Methods:
| Name | Description |
|---|---|
add_files |
Add files to the current selection programmatically. |
clear |
Clear the drop zone state (programmatic clear). |
eventFilter |
Filter events for the drop area. |
set_files |
Set the selected files programmatically. |
set_icon |
Set the icon displayed in the drop zone. |
show_file_tree |
Show the file tree (hide placeholder). |
show_placeholder |
Show the drop placeholder (hide tree). |
Attributes:
| Name | Type | Description |
|---|---|---|
accept_mode |
str
|
Return the accept mode. |
description |
str
|
Return the description text. |
extensions |
Optional[Set[str]]
|
Return the accepted extensions. |
file_tree |
Optional[QTreeWidget]
|
Return the file tree widget (if show_tree is True). |
has_files |
bool
|
Return whether files have been added. |
multiple |
bool
|
Return whether multiple selection is enabled. |
selected_files |
List[Path]
|
Return the list of selected files. |
title |
str
|
Return the title text. |