PySide6.QtWidgets.QFileDialog¶
- class QFileDialog¶
The
QFileDialog
class provides a dialog that allows users to select files or directories. More…Synopsis¶
Properties¶
acceptModeᅟ
- Accept mode of the dialogdefaultSuffixᅟ
- Suffix added to the filename if no other suffix was specifiedfileModeᅟ
- File mode of the dialogoptionsᅟ
- Various options that affect the look and feel of the dialogsupportedSchemesᅟ
- URL schemes that the file dialog should allow navigating toviewModeᅟ
- Way files and directories are displayed in the dialog
Methods¶
def
__init__()
def
acceptMode()
def
defaultSuffix()
def
directory()
def
directoryUrl()
def
fileMode()
def
filter()
def
history()
def
iconProvider()
def
itemDelegate()
def
labelText()
def
nameFilters()
def
open()
def
options()
def
proxyModel()
def
restoreState()
def
saveState()
def
selectFile()
def
selectUrl()
def
selectedFiles()
def
selectedUrls()
def
setAcceptMode()
def
setDirectory()
def
setFileMode()
def
setFilter()
def
setHistory()
def
setLabelText()
def
setNameFilter()
def
setNameFilters()
def
setOption()
def
setOptions()
def
setProxyModel()
def
setSidebarUrls()
def
setViewMode()
def
sidebarUrls()
def
testOption()
def
viewMode()
Signals¶
def
currentChanged()
def
fileSelected()
def
filesSelected()
def
filterSelected()
def
urlSelected()
def
urlsSelected()
Static functions¶
def
getOpenFileUrl()
def
getSaveFileUrl()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
The
QFileDialog
class enables a user to traverse the file system to select one or many files or a directory.The easiest way to create a
QFileDialog
is to use the static functions, such asgetOpenFileName()
.fileName = QFileDialog.getOpenFileName(self, tr("Open Image"), "/home/jana", tr("Image Files (*.png *.jpg *.bmp)"))
In the above example, a modal
QFileDialog
is created using a static function. The dialog initially displays the contents of the “/home/jana” directory, and displays files matching the patterns given in the string “Image Files (*.png *.jpg *.bmp)”. The parent of the file dialog is set to this, and the window title is set to “Open Image”.If you want to use multiple filters, separate each one with two semicolons. For example:
"Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"
You can create your own
QFileDialog
without using the static functions. By callingsetFileMode()
, you can specify what the user must select in the dialog:dialog = QFileDialog(self) dialog.setFileMode(QFileDialog.AnyFile)
In the above example, the mode of the file dialog is set to
AnyFile
, meaning that the user can select any file, or even specify a file that doesn’t exist. This mode is useful for creating a “Save As” file dialog. UseExistingFile
if the user must select an existing file, orDirectory
if only a directory can be selected. See theFileMode
enum for the complete list of modes.The
fileMode
property contains the mode of operation for the dialog; this indicates what types of objects the user is expected to select. UsesetNameFilter()
to set the dialog’s file filter. For example:dialog.setNameFilter(tr("Images (*.png *.xpm *.jpg)"))
In the above example, the filter is set to
"Images (*.png *.xpm *.jpg)"
. This means that only files with the extensionpng
,xpm
, orjpg
are shown in theQFileDialog
. You can apply several filters by usingsetNameFilters()
. UseselectNameFilter()
to select one of the filters you’ve given as the file dialog’s default filter.The file dialog has two view modes:
List
andDetail
.List
presents the contents of the current directory as a list of file and directory names.Detail
also displays a list of file and directory names, but provides additional information alongside each name, such as the file size and modification date. Set the mode withsetViewMode()
:dialog.setViewMode(QFileDialog.Detail)
The last important function you need to use when creating your own file dialog is
selectedFiles()
.fileNames = QStringList() if dialog.exec(): fileNames = dialog.selectedFiles()
In the above example, a modal file dialog is created and shown. If the user clicked OK, the file they selected is put in
fileName
.The dialog’s working directory can be set with
setDirectory()
. Each file in the current directory can be selected using theselectFile()
function.The Standard Dialogs example shows how to use
QFileDialog
as well as other built-in Qt dialogs.By default, a platform-native file dialog is used if the platform has one. In that case, the widgets that would otherwise be used to construct the dialog are not instantiated, so related accessors such as
layout()
anditemDelegate()
return null. Also, not all platforms show file dialogs with a title bar, so be aware that the caption text might not be visible to the user. You can set theDontUseNativeDialog
option or set the AA_DontUseNativeDialogs application attribute to ensure that the widget-based implementation is used instead of the native dialog.See also
QColorDialog
QFontDialog
Standard Dialogs Example- class ViewMode¶
This enum describes the view mode of the file dialog; that is, what information about each file is displayed.
Constant
Description
QFileDialog.Detail
Displays an icon, a name, and details for each item in the directory.
QFileDialog.List
Displays only an icon and a name for each item in the directory.
See also
- class FileMode¶
This enum is used to indicate what the user may select in the file dialog; that is, what the dialog returns if the user clicks OK.
Constant
Description
QFileDialog.AnyFile
The name of a file, whether it exists or not.
QFileDialog.ExistingFile
The name of a single existing file.
QFileDialog.Directory
The name of a directory. Both files and directories are displayed. However, the native Windows file dialog does not support displaying files in the directory chooser.
QFileDialog.ExistingFiles
The names of zero or more existing files.
See also
- class AcceptMode¶
Constant
Description
QFileDialog.AcceptOpen
QFileDialog.AcceptSave
- class DialogLabel¶
Constant
Description
QFileDialog.LookIn
QFileDialog.FileName
QFileDialog.FileType
QFileDialog.Accept
QFileDialog.Reject
- class Option¶
(inherits
enum.Flag
) Options that influence the behavior of the dialog.Constant
Description
QFileDialog.ShowDirsOnly
Only show directories. By default, both files and directories are shown. This option is only effective in the
Directory
file mode.QFileDialog.DontResolveSymlinks
Don’t resolve symlinks. By default, symlinks are resolved.
QFileDialog.DontConfirmOverwrite
Don’t ask for confirmation if an existing file is selected. By default, confirmation is requested. This option is only effective if
acceptMode
isAcceptSave
). It is furthermore not used on macOS for native file dialogs.QFileDialog.DontUseNativeDialog
Don’t use a platform-native file dialog, but the widget-based one provided by Qt. By default, a native file dialog is shown unless you use a subclass of
QFileDialog
that contains the Q_OBJECT macro, the global AA_DontUseNativeDialogs application attribute is set, or the platform does not have a native dialog of the type that you require. For the option to be effective, you must set it before changing other properties of the dialog, or showing the dialog.QFileDialog.ReadOnly
Indicates that the model is read-only.
QFileDialog.HideNameFilterDetails
Indicates if the file name filter details are hidden or not.
QFileDialog.DontUseCustomDirectoryIcons
Always use the default directory icon. Some platforms allow the user to set a different icon, but custom icon lookup might cause significant performance issues over network or removable drives. Setting this will enable the DontUseCustomDirectoryIcons option in
iconProvider()
. This enum value was added in Qt 5.2.See also
Note
Properties can be used directly when
from __feature__ import true_property
is used or via accessor functions otherwise.- property acceptModeᅟ: QFileDialog.AcceptMode¶
This property holds The accept mode of the dialog..
The action mode defines whether the dialog is for opening or saving files.
By default, this property is set to
AcceptOpen
.See also
- Access functions:
- property defaultSuffixᅟ: str¶
This property holds Suffix added to the filename if no other suffix was specified..
This property specifies a string that is added to the filename if it has no suffix yet. The suffix is typically used to indicate the file type (e.g. “txt” indicates a text file).
If the first character is a dot (‘.’), it is removed.
- Access functions:
- property fileModeᅟ: QFileDialog.FileMode¶
This property holds The file mode of the dialog..
The file mode defines the number and type of items that the user is expected to select in the dialog.
By default, this property is set to
AnyFile
.This function sets the labels for the
FileName
andAccept
DialogLabel
s. It is possible to set custom text after the call to setFileMode().See also
- Access functions:
- property optionsᅟ: Combination of QAbstractFileIconProvider.Option¶
This property holds The various options that affect the look and feel of the dialog..
By default, all options are disabled.
Options (particularly the
DontUseNativeDialog
option) should be set before changing dialog properties or showing the dialog.Setting options while the dialog is visible is not guaranteed to have an immediate effect on the dialog (depending on the option and on the platform).
Setting options after changing other properties may cause these values to have no effect.
See also
- Access functions:
- property supportedSchemesᅟ: list of strings¶
This property holds The URL schemes that the file dialog should allow navigating to..
Setting this property allows to restrict the type of URLs the user can select. It is a way for the application to declare the protocols it supports to fetch the file content. An empty list means that no restriction is applied (the default). Support for local files (“file” scheme) is implicit and always enabled; it is not necessary to include it in the restriction.
- Access functions:
- property viewModeᅟ: QFileDialog.ViewMode¶
This property holds The way files and directories are displayed in the dialog..
By default, the
Detail
mode is used to display information about files and directories.See also
- Access functions:
- __init__(parent, f)¶
- Parameters:
parent –
QWidget
f – Combination of
WindowType
Constructs a file dialog with the given
parent
and widgetflags
.- __init__([parent=None[, caption=""[, directory=""[, filter=""]]]])
- Parameters:
parent –
QWidget
caption – str
directory – str
filter – str
Constructs a file dialog with the given
parent
andcaption
that initially displays the contents of the specifieddirectory
. The contents of the directory are filtered before being shown in the dialog, using a semicolon-separated list of filters specified byfilter
.- acceptMode()¶
- Return type:
See also
Getter of property
acceptModeᅟ
.- currentChanged(path)¶
- Parameters:
path – str
When the current file changes for local operations, this signal is emitted with the new file name as the
path
parameter.See also
When the current file changes, this signal is emitted with the new file URL as the
url
parameter.See also
- defaultSuffix()¶
- Return type:
str
See also
Getter of property
defaultSuffixᅟ
.Returns the directory currently being displayed in the dialog.
See also
- directoryEntered(directory)¶
- Parameters:
directory – str
This signal is emitted for local operations when the user enters a
directory
.Returns the url of the directory currently being displayed in the dialog.
See also
This signal is emitted when the user enters a
directory
.- fileMode()¶
- Return type:
See also
Getter of property
fileModeᅟ
.- fileSelected(file)¶
- Parameters:
file – str
When the selection changes for local operations and the dialog is accepted, this signal is emitted with the (possibly empty) selected
file
.See also
- filesSelected(files)¶
- Parameters:
files – list of strings
When the selection changes for local operations and the dialog is accepted, this signal is emitted with the (possibly empty) list of
selected
files.See also
Returns the filter that is used when displaying files.
See also
- filterSelected(filter)¶
- Parameters:
filter – str
This signal is emitted when the user selects a
filter
.- static getExistingDirectory([parent=None[, caption=""[, dir=""[, options=QFileDialog.Option.ShowDirsOnly]]]])¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
This is a convenience static function that returns an existing directory selected by the user.
dir = QFileDialog.getExistingDirectory(self, tr("Open Directory"),() "/home", QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks)
This function creates a modal file dialog with the given
parent
widget. Ifparent
is notNone
, the dialog is shown centered over the parent widget.The dialog’s working directory is set to
dir
, and the caption is set tocaption
. Either of these can be an empty string in which case the current directory and a default caption are used respectively.The
options
argument holds various options about how to run the dialog. See theOption
enum for more information on the flags you can pass. To ensure a native file dialog,ShowDirsOnly
must be set.On Windows and macOS, this static function uses the native file dialog and not a
QFileDialog
. However, the native Windows file dialog does not support displaying files in the directory chooser. You need to pass theDontUseNativeDialog
option, or set the global \l{Qt::}{AA_DontUseNativeDialogs} application attribute to display files using aQFileDialog
.Note that the macOS native file dialog does not show a title bar.
On Unix/X11, the normal behavior of the file dialog is to resolve and follow symlinks. For example, if
/usr/tmp
is a symlink to/var/tmp
, the file dialog changes to/var/tmp
after entering/usr/tmp
. Ifoptions
includesDontResolveSymlinks
, the file dialog treats symlinks as regular directories.On Windows, the dialog spins a blocking modal event loop that does not dispatch any QTimers, and if
parent
is notNone
then it positions the dialog just below the parent’s title bar.Warning
Do not delete
parent
during the execution of the dialog. If you want to do this, you must create the dialog yourself using one of theQFileDialog
constructors.- static getExistingDirectoryUrl([parent=None[, caption=""[, dir=QUrl()[, options=QFileDialog.Option.ShowDirsOnly[, supportedSchemes=list()]]]]])¶
This is a convenience static function that returns an existing directory selected by the user. If the user presses Cancel, it returns an empty url.
The function is used similarly to
getExistingDirectory()
. In particularparent
,caption
,dir
andoptions
are used in exactly the same way.The main difference with
getExistingDirectory()
comes from the ability offered to the user to select a remote directory. That’s why the return type and the type ofdir
is QUrl.The
supportedSchemes
argument allows to restrict the type of URLs the user is able to select. It is a way for the application to declare the protocols it supports to fetch the file content. An empty list means that no restriction is applied (the default). Support for local files (“file” scheme) is implicit and always enabled; it is not necessary to include it in the restriction.When possible, this static function uses the native file dialog and not a
QFileDialog
. On platforms that don’t support selecting remote files, Qt allows to select only local files.- static getOpenFileName([parent=None[, caption=""[, dir=""[, filter=""[, selectedFilter=""[, options=QFileDialog.Options()]]]]]])¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
This is a convenience static function that returns an existing file selected by the user. If the user presses Cancel, it returns a null string.
fileName = QFileDialog.getOpenFileName(self, tr("Open File"),() "/home", tr("Images (*.png *.xpm *.jpg)"))
The function creates a modal file dialog with the given
parent
widget. Ifparent
is notNone
, the dialog is shown centered over the parent widget.The file dialog’s working directory is set to
dir
. Ifdir
includes a file name, the file is selected. Only files that match the givenfilter
are shown. The selected filter is set toselectedFilter
. The parametersdir
,selectedFilter
, andfilter
may be empty strings. If you want multiple filters, separate them with ‘;;’, for example:"Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"
The
options
argument holds various options about how to run the dialog. See theOption
enum for more information on the flags you can pass.The dialog’s caption is set to
caption
. Ifcaption
is not specified, then a default caption will be used.On Windows, and macOS, this static function uses the native file dialog and not a
QFileDialog
. Note that the macOS native file dialog does not show a title bar.On Windows the dialog spins a blocking modal event loop that does not dispatch any QTimers, and if
parent
is notNone
then it positions the dialog just below the parent’s title bar.On Unix/X11, the normal behavior of the file dialog is to resolve and follow symlinks. For example, if
/usr/tmp
is a symlink to/var/tmp
, the file dialog changes to/var/tmp
after entering/usr/tmp
. Ifoptions
includesDontResolveSymlinks
, the file dialog treats symlinks as regular directories.Warning
Do not delete
parent
during the execution of the dialog. If you want to do this, you must create the dialog yourself using one of theQFileDialog
constructors.- static getOpenFileNames([parent=None[, caption=""[, dir=""[, filter=""[, selectedFilter=""[, options=QFileDialog.Options()]]]]]])¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
This is a convenience static function that returns one or more existing files selected by the user.
files = QFileDialog.getOpenFileNames(() self, "Select one or more files to open", "/home", "Images (*.png *.xpm *.jpg)")
This function creates a modal file dialog with the given
parent
widget. Ifparent
is notNone
, the dialog is shown centered over the parent widget.The file dialog’s working directory is set to
dir
. Ifdir
includes a file name, the file is selected. The filter is set tofilter
so that only those files which match the filter are shown. The filter selected is set toselectedFilter
. The parametersdir
,selectedFilter
andfilter
can be empty strings. If you need multiple filters, separate them with ‘;;’, for instance:"Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"
The dialog’s caption is set to
caption
. Ifcaption
is not specified, then a default caption is used.On Windows and macOS, this static function uses the native file dialog and not a
QFileDialog
. Note that the macOS native file dialog does not show a title bar.On Windows the dialog spins a blocking modal event loop that does not dispatch any QTimers, and if
parent
is notNone
then it positions the dialog just below the parent’s title bar.On Unix/X11, the normal behavior of the file dialog is to resolve and follow symlinks. For example, if
/usr/tmp
is a symlink to/var/tmp
, the file dialog will change to/var/tmp
after entering/usr/tmp
. Theoptions
argument holds various options about how to run the dialog, see theOption
enum for more information on the flags you can pass.Warning
Do not delete
parent
during the execution of the dialog. If you want to do this, you must create the dialog yourself using one of theQFileDialog
constructors.- static getOpenFileUrl([parent=None[, caption=""[, dir=QUrl()[, filter=""[, selectedFilter=""[, options=QFileDialog.Options()[, supportedSchemes=list()]]]]]]])¶
This is a convenience static function that returns an existing file selected by the user. If the user presses Cancel, it returns an empty url.
The function is used similarly to
getOpenFileName()
. In particularparent
,caption
,dir
,filter
,selectedFilter
andoptions
are used in exactly the same way.The main difference with
getOpenFileName()
comes from the ability offered to the user to select a remote file. That’s why the return type and the type ofdir
is QUrl.The
supportedSchemes
argument allows to restrict the type of URLs the user is able to select. It is a way for the application to declare the protocols it will support to fetch the file content. An empty list means that no restriction is applied (the default). Support for local files (“file” scheme) is implicit and always enabled; it is not necessary to include it in the restriction.When possible, this static function uses the native file dialog and not a
QFileDialog
. On platforms that don’t support selecting remote files, Qt will allow to select only local files.- static getOpenFileUrls([parent=None[, caption=""[, dir=QUrl()[, filter=""[, selectedFilter=""[, options=QFileDialog.Options()[, supportedSchemes=list()]]]]]]])¶
This is a convenience static function that returns one or more existing files selected by the user. If the user presses Cancel, it returns an empty list.
The function is used similarly to
getOpenFileNames()
. In particularparent
,caption
,dir
,filter
,selectedFilter
andoptions
are used in exactly the same way.The main difference with
getOpenFileNames()
comes from the ability offered to the user to select remote files. That’s why the return type and the type ofdir
are respectively QList<QUrl> and QUrl.The
supportedSchemes
argument allows to restrict the type of URLs the user can select. It is a way for the application to declare the protocols it supports to fetch the file content. An empty list means that no restriction is applied (the default). Support for local files (“file” scheme) is implicit and always enabled; it is not necessary to include it in the restriction.When possible, this static function uses the native file dialog and not a
QFileDialog
. On platforms that don’t support selecting remote files, Qt will allow to select only local files.- static getSaveFileName([parent=None[, caption=""[, dir=""[, filter=""[, selectedFilter=""[, options=QFileDialog.Options()]]]]]])¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
This is a convenience static function that returns a file name selected by the user. The file does not have to exist.
It creates a modal file dialog with the given
parent
widget. Ifparent
is notNone
, the dialog will be shown centered over the parent widget.fileName = QFileDialog.getSaveFileName(self, tr("Save File"),() "/home/jana/untitled.png", tr("Images (*.png *.xpm *.jpg)"))
The file dialog’s working directory is set to
dir
. Ifdir
includes a file name, the file is selected. Only files that match thefilter
are shown. The filter selected is set toselectedFilter
. The parametersdir
,selectedFilter
, andfilter
may be empty strings. Multiple filters are separated with ‘;;’. For instance:"Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"
The
options
argument holds various options about how to run the dialog, see theOption
enum for more information on the flags you can pass.The default filter can be chosen by setting
selectedFilter
to the desired value.The dialog’s caption is set to
caption
. Ifcaption
is not specified, a default caption is used.On Windows, and macOS, this static function uses the native file dialog and not a
QFileDialog
.On Windows the dialog spins a blocking modal event loop that does not dispatch any QTimers, and if
parent
is notNone
then it positions the dialog just below the parent’s title bar. On macOS, with its native file dialog, the filter argument is ignored.On Unix/X11, the normal behavior of the file dialog is to resolve and follow symlinks. For example, if
/usr/tmp
is a symlink to/var/tmp
, the file dialog changes to/var/tmp
after entering/usr/tmp
. Ifoptions
includesDontResolveSymlinks
, the file dialog treats symlinks as regular directories.Warning
Do not delete
parent
during the execution of the dialog. If you want to do this, you must create the dialog yourself using one of theQFileDialog
constructors.- static getSaveFileUrl([parent=None[, caption=""[, dir=QUrl()[, filter=""[, selectedFilter=""[, options=QFileDialog.Options()[, supportedSchemes=list()]]]]]]])¶
This is a convenience static function that returns a file selected by the user. The file does not have to exist. If the user presses Cancel, it returns an empty url.
The function is used similarly to
getSaveFileName()
. In particularparent
,caption
,dir
,filter
,selectedFilter
andoptions
are used in exactly the same way.The main difference with
getSaveFileName()
comes from the ability offered to the user to select a remote file. That’s why the return type and the type ofdir
is QUrl.The
supportedSchemes
argument allows to restrict the type of URLs the user can select. It is a way for the application to declare the protocols it supports to save the file content. An empty list means that no restriction is applied (the default). Support for local files (“file” scheme) is implicit and always enabled; it is not necessary to include it in the restriction.When possible, this static function uses the native file dialog and not a
QFileDialog
. On platforms that don’t support selecting remote files, Qt will allow to select only local files.- history()¶
- Return type:
list of strings
Returns the browsing history of the filedialog as a list of paths.
See also
- iconProvider()¶
- Return type:
Returns the icon provider used by the filedialog.
See also
- itemDelegate()¶
- Return type:
Returns the item delegate used to render the items in the views in the filedialog.
See also
- labelText(label)¶
- Parameters:
label –
DialogLabel
- Return type:
str
Returns the text shown in the filedialog in the specified
label
.See also
- mimeTypeFilters()¶
- Return type:
list of strings
Returns the MIME type filters that are in operation on this file dialog.
See also
- nameFilters()¶
- Return type:
list of strings
Returns the file type filters that are in operation on this file dialog.
See also
This function shows the dialog, and connects the slot specified by
receiver
andmember
to the signal that informs about selection changes. If thefileMode
isExistingFiles
, this is thefilesSelected()
signal, otherwise it is thefileSelected()
signal.The signal is disconnected from the slot when the dialog is closed.
- proxyModel()¶
- Return type:
Returns the proxy model used by the file dialog. By default no proxy is set.
See also
- restoreState(state)¶
- Parameters:
state –
QByteArray
- Return type:
bool
Restores the dialogs’s layout, history and current directory to the
state
specified.Typically this is used in conjunction with QSettings to restore the size from a past session.
Returns
false
if there are errors- static saveFileContent(fileContent, fileNameHint[, parent=None])¶
- Parameters:
fileContent –
QByteArray
fileNameHint – str
parent –
QWidget
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
This is a convenience static function that saves
fileContent
to a file, using a file name and location chosen by the user.fileNameHint
can be provided to suggest a file name to the user.Use this function to save content to local files on Qt for WebAssembly, if the web sandbox restricts file access. Its implementation enables displaying a native file dialog in the browser, where the user specifies an output file based on the
fileNameHint
argument.parent
is ignored on Qt for WebAssembly. Passparent
on other platforms, to make the popup a child of another widget. If the platform doesn’t support native file dialogs, the function falls back toQFileDialog
.The function is asynchronous and returns immediately.
QByteArray imageData # obtained from e.g. QImage.save() QFileDialog.saveFileContent(imageData, "myimage.png") # with filename hint # OR QFileDialog.saveFileContent(imageData) # no filename hint
- saveState()¶
- Return type:
Saves the state of the dialog’s layout, history and current directory.
Typically this is used in conjunction with QSettings to remember the size for a future session. A version number is stored as part of the data.
- selectFile(filename)¶
- Parameters:
filename – str
Selects the given
filename
in the file dialog.See also
- selectMimeTypeFilter(filter)¶
- Parameters:
filter – str
Sets the current MIME type
filter
.- selectNameFilter(filter)¶
- Parameters:
filter – str
Sets the current file type
filter
. Multiple filters can be passed infilter
by separating them with semicolons or spaces.Selects the given
url
in the file dialog.- selectedFiles()¶
- Return type:
list of strings
Returns a list of strings containing the absolute paths of the selected files in the dialog. If no files are selected, or the mode is not
ExistingFiles
orExistingFile
, selectedFiles() contains the current path in the viewport.See also
- selectedMimeTypeFilter()¶
- Return type:
str
Returns The mimetype of the file that the user selected in the file dialog.
- selectedNameFilter()¶
- Return type:
str
Returns the filter that the user selected in the file dialog.
See also
Returns a list of urls containing the selected files in the dialog. If no files are selected, or the mode is not
ExistingFiles
orExistingFile
, selectedUrls() contains the current path in the viewport.See also
- setAcceptMode(mode)¶
- Parameters:
mode –
AcceptMode
See also
Setter of property
acceptModeᅟ
.- setDefaultSuffix(suffix)¶
- Parameters:
suffix – str
See also
Setter of property
defaultSuffixᅟ
.This is an overloaded function.
- setDirectory(directory)
- Parameters:
directory – str
Sets the file dialog’s current
directory
.Note
On iOS, if you set
directory
to QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).last(), a native image picker dialog is used for accessing the user’s photo album. The filename returned can be loaded using QFile and related APIs. For this to be enabled, the Info.plist assigned to QMAKE_INFO_PLIST in the project file must contain the keyNSPhotoLibraryUsageDescription
. See Info.plist documentation from Apple for more information regarding this key. This feature was added in Qt 5.5.See also
Sets the file dialog’s current
directory
url.Note
The non-native
QFileDialog
supports only local files.Note
On Windows, it is possible to pass URLs representing one of the virtual folders, such as “Computer” or “Network”. This is done by passing a QUrl using the scheme
clsid
followed by the CLSID value with the curly braces removed. For example the URLclsid:374DE290-123F-4565-9164-39C4925E467B
denotes the download location. For a complete list of possible values, see the MSDN documentation on KNOWNFOLDERID . This feature was added in Qt 5.5.See also
Setter of property
fileModeᅟ
.Sets the filter used by the model to
filters
. The filter is used to specify the kind of files that should be shown.See also
- setHistory(paths)¶
- Parameters:
paths – list of strings
Sets the browsing history of the filedialog to contain the given
paths
.See also
- setIconProvider(provider)¶
- Parameters:
provider –
QAbstractFileIconProvider
Sets the icon provider used by the filedialog to the specified
provider
.See also
- setItemDelegate(delegate)¶
- Parameters:
delegate –
QAbstractItemDelegate
Sets the item delegate used to render items in the views in the file dialog to the given
delegate
.Any existing delegate will be removed, but not deleted.
QFileDialog
does not take ownership ofdelegate
.Warning
You should not share the same instance of a delegate between views. Doing so can cause incorrect or unintuitive editing behavior since each view connected to a given delegate may receive the
closeEditor()
signal, and attempt to access, modify or close an editor that has already been closed.Note that the model used is QFileSystemModel. It has custom item data roles, which is described by the Roles enum. You can use a
QFileIconProvider
if you only want custom icons.- setLabelText(label, text)¶
- Parameters:
label –
DialogLabel
text – str
Sets the
text
shown in the filedialog in the specifiedlabel
.See also
- setMimeTypeFilters(filters)¶
- Parameters:
filters – list of strings
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Sets the
filters
used in the file dialog, from a list of MIME types.Convenience method for
setNameFilters()
. Uses QMimeType to create a name filter from the glob patterns and description defined in each MIME type.Use application/octet-stream for the “All files (*)” filter, since that is the base MIME type for all files.
Calling setMimeTypeFilters overrides any previously set name filters, and changes the return value of
nameFilters()
.def mimeTypeFilters({"image/jpeg",*.jpe): "image/png", // will show "PNG image (*.png)" "application/octet-stream" // will show "All files (*)" }) dialog = QFileDialog(self) dialog.setMimeTypeFilters(mimeTypeFilters) dialog.exec()
See also
- setNameFilter(filter)¶
- Parameters:
filter – str
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Sets the filter used in the file dialog to the given
filter
.If
filter
contains a pair of parentheses containing one or more filename-wildcard patterns, separated by spaces, then only the text contained in the parentheses is used as the filter. This means that these calls are all equivalent:dialog.setNameFilter("All C++ files (*.cpp *.cc *.C *.cxx *.c++)") dialog.setNameFilter("*.cpp *.cc *.C *.cxx *.c++")
Note
With Android’s native file dialog, the mime type matching the given name filter is used because only mime types are supported.
See also
- setNameFilters(filters)¶
- Parameters:
filters – list of strings
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Sets the
filters
used in the file dialog.Note that the filter *.* is not portable, because the historical assumption that the file extension determines the file type is not consistent on every operating system. It is possible to have a file with no dot in its name (for example,
Makefile
). In a native Windows file dialog, *.* matches such files, while in other types of file dialogs it might not match. So, it’s better to use * if you mean to select any file.QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" }) dialog = QFileDialog(self) dialog.setNameFilters(filters) dialog.exec()
setMimeTypeFilters()
has the advantage of providing all possible name filters for each file type. For example, JPEG images have three possible extensions; if your application can open such files, selecting theimage/jpeg
mime type as a filter allows you to open all of them.See also
Sets the given
option
to be enabled ifon
is true; otherwise, clears the givenoption
.Options (particularly the
DontUseNativeDialog
option) should be set before changing dialog properties or showing the dialog.Setting options while the dialog is visible is not guaranteed to have an immediate effect on the dialog (depending on the option and on the platform).
Setting options after changing other properties may cause these values to have no effect.
See also
- setProxyModel(model)¶
- Parameters:
model –
QAbstractProxyModel
Sets the model for the views to the given
proxyModel
. This is useful if you want to modify the underlying model; for example, to add columns, filter data or add drives.Any existing proxy model is removed, but not deleted. The file dialog takes ownership of the
proxyModel
.See also
- setSidebarUrls(urls)¶
- Parameters:
urls – .list of QUrl
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Sets the
urls
that are located in the sidebar.For instance:
urls = QList() urls << QUrl.fromLocalFile("/Users/foo/Code/qt5") << QUrl.fromLocalFile(QStandardPaths.standardLocations(QStandardPaths.MusicLocation).first()) dialog = QFileDialog() dialog.setSidebarUrls(urls) dialog.setFileMode(QFileDialog.AnyFile) if dialog.exec(): # ...
Then the file dialog looks like this:
See also
- setSupportedSchemes(schemes)¶
- Parameters:
schemes – list of strings
See also
Setter of property
supportedSchemesᅟ
.Setter of property
viewModeᅟ
.Returns a list of urls that are currently in the sidebar
See also
- supportedSchemes()¶
- Return type:
list of strings
See also
Getter of property
supportedSchemesᅟ
.Returns
true
if the givenoption
is enabled; otherwise, returns false.See also
When the selection changes and the dialog is accepted, this signal is emitted with the (possibly empty) selected
url
.See also
- urlsSelected(urls)¶
- Parameters:
urls – .list of QUrl
When the selection changes and the dialog is accepted, this signal is emitted with the (possibly empty) list of selected
urls
.See also
- viewMode()¶
- Return type:
See also
Getter of property
viewModeᅟ
.