Skip to content

File Path Widget

A widget for selecting file or folder paths with a browse button and path validation.

Preview

FXFilePathWidget

FXFilePathWidget

Bases: FXThemeAware, QWidget

A line edit with integrated browse button for file/folder selection.

This widget provides: - File or folder mode selection - Drag & drop support - Path validation indicator - Browse button with file dialog

Parameters:

Name Type Description Default

parent

Optional[QWidget]

Parent widget.

None

mode

str

Selection mode ('file', 'files', 'folder', 'save').

'file'

placeholder

str

Placeholder text.

'Select path...'

file_filter

str

File filter for file dialogs (e.g., "Images (*.png *.jpg)").

'All Files (*)'

default_path

Optional[str]

Default path for the file dialog.

None

validate

bool

Whether to show validation indicator.

True
Signals

path_changed: Emitted when the path changes. path_valid: Emitted with True/False when validation state changes.

Examples:

>>> path_widget = FXFilePathWidget(mode='file', file_filter="Python (*.py)")
>>> path_widget.path_changed.connect(lambda p: print(f"Path: {p}"))
>>>
>>> # Folder mode
>>> folder_widget = FXFilePathWidget(mode='folder')

Methods:

Name Description
clear

Clear the path input.

dragEnterEvent

Handle drag enter for file drops.

dropEvent

Handle file drop.

get_path

Return the current path.

is_valid

Return whether the current path is valid.

set_file_filter

Set the file filter.

set_mode

Set the selection mode.

set_path

Set the path.

Attributes:

Name Type Description
path str

Return the current path.

path property writable

path: str

Return the current path.

clear

clear() -> None

Clear the path input.

dragEnterEvent

dragEnterEvent(event) -> None

Handle drag enter for file drops.

dropEvent

dropEvent(event) -> None

Handle file drop.

get_path

get_path() -> str

Return the current path.

is_valid

is_valid() -> bool

Return whether the current path is valid.

set_file_filter

set_file_filter(filter_str: str) -> None

Set the file filter.

Parameters:

Name Type Description Default

filter_str

str

File filter string (e.g., "Images (*.png *.jpg)").

required

set_mode

set_mode(mode: str) -> None

Set the selection mode.

Parameters:

Name Type Description Default

mode

str

Selection mode ('file', 'files', 'folder', 'save').

required

set_path

set_path(path: str) -> None

Set the path.

Parameters:

Name Type Description Default

path

str

The file or folder path.

required