Class: QgsFileWidget

A widget for selecting a file or a folder.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsFileWidget

Base classes

QWidget

QObject

QPaintDevice

Subclasses

QgsExternalStorageFileWidget

A widget for selecting a file or a folder and optionally storing it to an external storage backend.

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[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

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])

virtual 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)

virtual 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

virtual updateLayout(self)[source]

Update buttons visibility

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

See also

setUseLink()

Return type:

bool