Class: QgsFileWidget¶
A widget for selecting a file or a folder.
Class Hierarchy¶
Base classes¶
Subclasses¶
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.
See also
- Return type:
bool
- 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
See also
- Return type:
str
- fileWidgetButtonVisible(self) bool[source]¶
Returns
Trueif the tool button is shown.See also
- Return type:
bool
- fullUrl(self) bool[source]¶
Returns
Trueif the links shown use the full path.See also
- Return type:
bool
- static isMultiFiles(path: str | None) bool[source]¶
Returns true if
pathis 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
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.
See also
- Return type:
- selectedFilter(self) str[source]¶
Returns the selected filter from the last opened file dialog.
See also
- 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
See also
- 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
- Parameters:
defaultRoot (Optional[str])
- setDialogTitle(self, title: str | None)[source]¶
Sets the
titleto 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
- Parameters:
title (Optional[str])
- setFilePath(self, path: str | None)[source]¶
Sets the current file
path.See also
- Parameters:
path (Optional[str])
- setFilePaths(self, filePaths: Iterable[str | None])[source]¶
Update filePath according to
filePathslist- Parameters:
filePaths (Iterable[Optional[str]])
- setFileWidgetButtonVisible(self, visible: bool)[source]¶
Sets whether the tool button is
visible.See also
- 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
- 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
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.
See also
- Parameters:
relativeStorage (QgsFileWidget.RelativeStorage)
- virtual setSelectedFileNames(self, fileNames: Iterable[str | None])[source]¶
Called whenever user select
fileNamesfrom dialog- Parameters:
fileNames (Iterable[Optional[str]])
- setSelectedFilter(self, selectedFilter: str | None)[source]¶
Sets the selected filter when the file dialog opens.
See also
- Parameters:
selectedFilter (Optional[str])
- setStorageMode(self, storageMode: QgsFileWidget.StorageMode)[source]¶
Sets the widget’s storage mode (i.e. file or directory).
See also
- Parameters:
storageMode (QgsFileWidget.StorageMode)
- setUseLink(self, useLink: bool)[source]¶
Sets whether the file path will be shown as a link.
See also
- Parameters:
useLink (bool)
- static splitFilePaths(path: str | None) List[str][source]¶
Split the the quoted and space separated
pathand returns a list of strings.See also
- 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
- Return type:
- 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