QgsFileWidget class
The QgsFileWidget class creates a widget for selecting a file or a folder.
Contents
Public types
- enum RelativeStorage { Absolute, RelativeProject, RelativeDefaultPath }
- The RelativeStorage enum determines if path is absolute, relative to the current project path or relative to a defined default path.
- enum StorageMode { GetFile, GetDirectory, GetMultipleFiles, SaveFile }
- The StorageMode enum determines if the file picker should pick files or directories.
Public static functions
- static auto splitFilePaths(const QString& path) -> QStringList
- Split the the quoted and space separated path and returns a QString list.
Constructors, destructors, conversion operators
- QgsFileWidget(QWidget* parent = nullptr) explicit
- QgsFileWidget creates a widget for selecting a file or a folder.
Public functions
- auto confirmOverwrite() const -> bool
- Returns whether a confirmation will be shown when overwriting an existing file.
- auto defaultRoot() const -> QString
- returns the default root path
- auto dialogTitle() const -> QString
- returns the open file dialog title
- auto filePath() -> QString
- 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"')
- auto fileWidgetButtonVisible() const -> bool
- determines if the tool button is shown
- auto filter() const -> QString
- returns the filters used for QDialog::getOpenFileName
- auto fullUrl() const -> bool
- returns if the links shows the full path or not
- auto lineEdit() -> QgsFilterLineEdit*
- 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.
-
auto relativeStorage() const -> QgsFileWidget::
RelativeStorage - returns if the relative path is with respect to the project path or the default path
- auto selectedFilter() const -> QString
- Returns the selected filter from the last opened file dialog.
- void setConfirmOverwrite(bool confirmOverwrite)
- Sets whether a confirmation to overwrite an existing file will appear.
- void setDefaultRoot(const QString& defaultRoot)
- determines the default root path used as the first shown location when picking a file and used if the RelativeStorage is RelativeDefaultPath
- void setDialogTitle(const QString& title)
- setDialogTitle defines the open file dialog title
- void setFilePath(QString path)
- Sets the file path.
- void setFileWidgetButtonVisible(bool visible)
- determines if the tool button is shown
- void setFilter(const QString& filter)
- setFilter sets the filter used by the model to filters.
- void setFullUrl(bool fullUrl)
- determines if the links shows the full path or not
- void setReadOnly(bool readOnly)
- defines if the widget is readonly
-
void setRelativeStorage(QgsFileWidget::
RelativeStorage relativeStorage) - determines if the relative path is with respect to the project path or the default path
- void setSelectedFilter(const QString& selectedFilter)
- Sets the selected filter when the file dialog opens.
-
void setStorageMode(QgsFileWidget::
StorageMode storageMode) - determines the storage mode (i.e. file or directory)
- void setUseLink(bool useLink)
- determines if the file path will be shown as a link
-
auto storageMode() const -> QgsFileWidget::
StorageMode - returns the storage mode (i.e. file or directory)
- auto useLink() const -> bool
- determines if the file path will be shown as a link
Signals
- void fileChanged(const QString&)
- emitted as soon as the current file or directory is changed
Enum documentation
enum QgsFileWidget:: StorageMode
The StorageMode enum determines if the file picker should pick files or directories.
| Enumerators | |
|---|---|
| GetFile | |
| GetDirectory |
Select a single file. |
| GetMultipleFiles |
Select a directory. |
| SaveFile |
Select multiple files. |
Function documentation
static QStringList QgsFileWidget:: splitFilePaths(const QString& path)
Split the the quoted and space separated path and returns a QString list.
QString QgsFileWidget:: filePath()
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"')
QgsFilterLineEdit* QgsFileWidget:: 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.
void QgsFileWidget:: setConfirmOverwrite(bool confirmOverwrite)
Sets whether a confirmation to overwrite an existing file will appear.
| Parameters | |
|---|---|
| confirmOverwrite | If set to true, an overwrite confirmation will be shown |
By default, a confirmation will appear.
void QgsFileWidget:: setDialogTitle(const QString& title)
setDialogTitle defines the open file dialog title
void QgsFileWidget:: setFilter(const QString& filter)
setFilter sets the filter used by the model to filters.
| Parameters | |
|---|---|
| filter | Only files that match the given filter are shown, it may be an empty string. If you want multiple filters, separate them with ';;', |
The filter is used to specify the kind of files that should be shown.