Skip to content

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
parent
Optional[QWidget]

Parent widget.

None
title
str

Main title text displayed in the drop zone.

'Drag and Drop Files Here'
description
str

Description text displayed below the title.

'or use the Browse Files... button below'
accept_mode
str

What to accept - 'files', 'folders', or 'both'.

'files'
extensions
Optional[Set[str]]

Set of allowed file extensions (e.g., {'.png', '.jpg'}). If None, all extensions are accepted.

None
multiple
bool

Whether to allow multiple file/folder selection.

True
icon_name
str

Icon name to display (default: 'upload_file').

'upload_file'
show_formats
bool

Whether to display accepted formats below title.

True
show_buttons
bool

Whether to show Browse/Clear buttons.

True
show_tree
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.

Attributes
accept_mode property writable
accept_mode: str

Return the accept mode.

description property writable
description: str

Return the description text.

extensions property writable
extensions: Optional[Set[str]]

Return the accepted extensions.

file_tree property
file_tree: Optional[QTreeWidget]

Return the file tree widget (if show_tree is True).

has_files property
has_files: bool

Return whether files have been added.

multiple property writable
multiple: bool

Return whether multiple selection is enabled.

selected_files property
selected_files: List[Path]

Return the list of selected files.

title property writable
title: str

Return the title text.

Functions
add_files
add_files(paths: List[Path]) -> None

Add files to the current selection programmatically.

Parameters:

Name Type Description Default
paths List[Path]

List of paths to add.

required
clear
clear() -> None

Clear the drop zone state (programmatic clear).

eventFilter
eventFilter(obj, event) -> bool

Filter events for the drop area.

set_files
set_files(paths: List[Path]) -> None

Set the selected files programmatically.

Parameters:

Name Type Description Default
paths List[Path]

List of paths to set as selected.

required
set_icon
set_icon(icon_name: str) -> None

Set the icon displayed in the drop zone.

Parameters:

Name Type Description Default
icon_name str

Name of the icon (from fxicons).

required
show_file_tree
show_file_tree() -> None

Show the file tree (hide placeholder).

show_placeholder
show_placeholder() -> None

Show the drop placeholder (hide tree).

Functions

example

example() -> None

Demonstrate the FXDropZone widget.