Class: QgsFileWidget

The QgsFileWidget class creates a widget for selecting a file or a folder.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsFileWidget

Base classes

QWidget

QObject

QPaintDevice

Subclasses

QgsExternalStorageFileWidget

The QgsExternalStorageFileWidget class creates a widget for selecting a file or a folder and stores it to a given external storage backend if defined

Methods

confirmOverwrite

Returns whether a confirmation will be shown when overwriting an existing file.

defaultRoot

Returns the default root path.

dialogTitle

Returns the open file dialog title.

filePath

Returns the current file path(s).

fileWidgetButtonVisible

Returns True if the tool button is shown.

filter

returns the filters used for QDialog.getOpenFileName

fullUrl

Returns True if the links shown use the full path.

lineEdit

Returns a pointer to the widget's line edit, which can be used to customize the appearance and behavior of the line edit portion of the widget.

options

Returns the additional options used for QFileDialog.

relativePath

Returns a filePath with relative path options applied (or not) !

relativeStorage

Returns if the relative path is with respect to the project path or the default path.

selectedFilter

Returns the selected filter from the last opened file dialog.

setConfirmOverwrite

Sets whether a confirmation to overwrite an existing file will appear.

setDefaultRoot

Returns the default root path used as the first shown location when picking a file and used if the RelativeStorage is RelativeDefaultPath.

setDialogTitle

Sets the title to use for the open file dialog.

setFilePath

Sets the current file path.

setFilePaths

Update filePath according to filePaths list

setFileWidgetButtonVisible

Sets whether the tool button is visible.

setFilter

setFilter sets the filter used by the model to filters.

setFullUrl

Sets whether links shown use the full path.

setOptions

Set additional options used for QFileDialog.

setReadOnly

Sets whether the widget should be read only.

setRelativeStorage

Sets whether the relative path is with respect to the project path or the default path.

setSelectedFileNames

Called whenever user select fileNames from dialog

setSelectedFilter

Sets the selected filter when the file dialog opens.

setStorageMode

Sets the widget's storage mode (i.e. file or directory).

setUseLink

Sets whether the file path will be shown as a link.

storageMode

Returns the widget's storage mode (i.e. file or directory).

toUrl

returns a HTML code with a link to the given file path

updateLayout

Update buttons visibility

useLink

Returns True if the file path will be shown as a link.

Static Methods

isMultiFiles

Returns true if path is a multifiles

splitFilePaths

Split the the quoted and space separated path and returns a list of strings.

Signals

fileChanged

Emitted whenever the current file or directory path is changed.

Attributes

Absolute

GetDirectory

GetFile

GetMultipleFiles

RelativeDefaultPath

RelativeProject

SaveFile

class qgis.gui.QgsFileWidget[source]

Bases: QWidget

__init__(parent: QWidget | None = None)

QgsFileWidget creates a widget for selecting a file or a folder.

Parameters:

parent (Optional[QWidget] = None)

Absolute = 0
GetDirectory = 1
GetFile = 0
GetMultipleFiles = 2
RelativeDefaultPath = 2
RelativeProject = 1
class RelativeStorage

Bases: int

SaveFile = 3
class StorageMode

Bases: int

confirmOverwrite(self) bool[source]

Returns whether a confirmation will be shown when overwriting an existing file.

Return type:

bool

defaultRoot(self) str[source]

Returns the default root path.

See also

setDefaultRoot()

Return type:

str

dialogTitle(self) str[source]

Returns the open file dialog title.

See also

setDialogTitle()

Return type:

str

signal fileChanged(path: str)[source]

Emitted whenever the current file or directory path is changed.

Parameters:

path (str)

filePath(self) str[source]

Returns the current file path(s).

When multiple files are selected they are quoted and separated by a single space (for example: ‘”/path/foo” “path/bar”’)

See also

setFilePath()

See also

splitFilePaths()

Return type:

str

fileWidgetButtonVisible(self) bool[source]

Returns True if the tool button is shown.

Return type:

bool

filter(self) str[source]

returns the filters used for QDialog.getOpenFileName

Return type:

str

fullUrl(self) bool[source]

Returns True if the links shown use the full path.

See also

setFullUrl()

Return type:

bool

static isMultiFiles(path: str | None) bool[source]

Returns true if path is a multifiles

Parameters:

path (Optional[str])

Return type:

bool

lineEdit(self) QgsFilterLineEdit | None[source]

Returns a pointer to the widget’s line edit, which can be used to customize the appearance and behavior of the line edit portion of the widget.

Return type:

Optional[QgsFilterLineEdit]

options(self) QFileDialog.Options[source]

Returns the additional options used for QFileDialog.

See also

setOptions()

Added in version 3.14.

Return type:

QFileDialog.Options

relativePath(self, filePath: str | None, removeRelative: bool) str[source]

Returns a filePath with relative path options applied (or not) !

Parameters:
  • filePath (Optional[str])

  • removeRelative (bool)

Return type:

str

relativeStorage(self) QgsFileWidget.RelativeStorage[source]

Returns if the relative path is with respect to the project path or the default path.

Return type:

QgsFileWidget.RelativeStorage

selectedFilter(self) str[source]

Returns the selected filter from the last opened file dialog.

Return type:

str

setConfirmOverwrite(self, confirmOverwrite: bool)[source]

Sets whether a confirmation to overwrite an existing file will appear.

By default, a confirmation will appear.

Parameters:

confirmOverwrite (bool) – If set to True, an overwrite confirmation will be shown

setDefaultRoot(self, defaultRoot: str | None)[source]

Returns the default root path used as the first shown location when picking a file and used if the RelativeStorage is RelativeDefaultPath.

See also

defaultRoot()

Parameters:

defaultRoot (Optional[str])

setDialogTitle(self, title: str | None)[source]

Sets the title to use for the open file dialog.

Note

If not defined, the title is “Select a file” or “Select a directory” or “Select one or more files” depending on the configuration.

See also

dialogTitle()

Parameters:

title (Optional[str])

setFilePath(self, path: str | None)[source]

Sets the current file path.

See also

filePath()

Parameters:

path (Optional[str])

setFilePaths(self, filePaths: Iterable[str | None])[source]

Update filePath according to filePaths list

Parameters:

filePaths (Iterable[Optional[str]])

setFileWidgetButtonVisible(self, visible: bool)[source]

Sets whether the tool button is visible.

Parameters:

visible (bool)

setFilter(self, filter: str | None)[source]

setFilter sets the filter used by the model to filters. The filter is used to specify the kind of files that should be shown.

Parameters:

filter (Optional[str]) – Only files that match the given filter are shown, it may be an empty string. If you want multiple filters, separate them with ‘;;’,

setFullUrl(self, fullUrl: bool)[source]

Sets whether links shown use the full path.

See also

fullUrl()

Parameters:

fullUrl (bool)

setOptions(self, options: QFileDialog.Options | QFileDialog.Option)[source]

Set additional options used for QFileDialog.

These options affect the look and feel of the QFileDialog shown when a user is interactively browsing for paths.

See also

options()

Added in version 3.14.

Parameters:

options (Union[QFileDialog.Options, QFileDialog.Option])

setReadOnly(self, readOnly: bool)[source]

Sets whether the widget should be read only.

Parameters:

readOnly (bool)

setRelativeStorage(self, relativeStorage: QgsFileWidget.RelativeStorage)[source]

Sets whether the relative path is with respect to the project path or the default path.

Parameters:

relativeStorage (QgsFileWidget.RelativeStorage)

setSelectedFileNames(self, fileNames: Iterable[str | None])[source]

Called whenever user select fileNames from dialog

Parameters:

fileNames (Iterable[Optional[str]])

setSelectedFilter(self, selectedFilter: str | None)[source]

Sets the selected filter when the file dialog opens.

See also

selectedFilter()

Parameters:

selectedFilter (Optional[str])

setStorageMode(self, storageMode: QgsFileWidget.StorageMode)[source]

Sets the widget’s storage mode (i.e. file or directory).

See also

storageMode()

Parameters:

storageMode (QgsFileWidget.StorageMode)

Sets whether the file path will be shown as a link.

See also

useLink()

Parameters:

useLink (bool)

static splitFilePaths(path: str | None) List[str][source]

Split the the quoted and space separated path and returns a list of strings.

See also

filePath()

Parameters:

path (Optional[str])

Return type:

List[str]

storageMode(self) QgsFileWidget.StorageMode[source]

Returns the widget’s storage mode (i.e. file or directory).

See also

setStorageMode()

Return type:

QgsFileWidget.StorageMode

toUrl(self, path: str | None) str[source]

returns a HTML code with a link to the given file path

Parameters:

path (Optional[str])

Return type:

str

updateLayout(self)[source]

Update buttons visibility

Returns True if the file path will be shown as a link.

See also

setUseLink()

Return type:

bool