QDirModel¶
Synopsis¶
Functions¶
def
fileIcon
(index)def
fileInfo
(index)def
fileName
(index)def
filePath
(index)def
filter
()def
iconProvider
()def
index
(path[, column=0])def
isDir
(index)def
isReadOnly
()def
lazyChildCount
()def
mkdir
(parent, name)def
nameFilters
()def
remove
(index)def
resolveSymlinks
()def
rmdir
(index)def
setFilter
(filters)def
setIconProvider
(provider)def
setLazyChildCount
(enable)def
setNameFilters
(filters)def
setReadOnly
(enable)def
setResolveSymlinks
(enable)def
setSorting
(sort)def
sorting
()
Slots¶
def
refresh
([parent=QModelIndex()])
Detailed Description¶
The usage of
QDirModel
is not recommended anymore. TheQFileSystemModel
class is a more performant alternative.This class provides access to the local filesystem, providing functions for renaming and removing files and directories, and for creating new directories. In the simplest case, it can be used with a suitable display widget as part of a browser or filer.
QDirModel
keeps a cache with file information. The cache needs to be updated withrefresh()
.
QDirModel
can be accessed using the standard interface provided byQAbstractItemModel
, but it also provides some convenience functions that are specific to a directory model. ThefileInfo()
andisDir()
functions provide information about the underlying files and directories related to items in the model.Directories can be created and removed using
mkdir()
,rmdir()
, and the model will be automatically updated to take the changes into account.Note
QDirModel
requires an instance ofQApplication
.
- class PySide2.QtWidgets.QDirModel([parent=None])¶
Note
This constructor is deprecated.
PySide2.QtWidgets.QDirModel(nameFilters, filters, sort[, parent=None])
Note
This constructor is deprecated.
- param parent:
- param nameFilters:
list of strings
- param filters:
Filters
- param sort:
SortFlags
Constructs a directory model with the given
parent
.Constructs a new directory model with the given
parent
. Only those files matching thenameFilters
and thefilters
are included in the model. The sort order is given by thesort
flags.
- PySide2.QtWidgets.QDirModel.Roles¶
Constant
Description
QDirModel.FileIconRole
QDirModel.FilePathRole
QDirModel.FileNameRole
- PySide2.QtWidgets.QDirModel.fileIcon(index)¶
- Parameters:
index –
PySide2.QtCore.QModelIndex
- Return type:
Returns the icons for the item stored in the model under the given
index
.
- PySide2.QtWidgets.QDirModel.fileInfo(index)¶
- Parameters:
index –
PySide2.QtCore.QModelIndex
- Return type:
Returns the file information for the specified model
index
.Note
If the model index represents a symbolic link in the underlying filing system, the file information returned will contain information about the symbolic link itself, regardless of whether
resolveSymlinks
is enabled or not.See also
symLinkTarget()
- PySide2.QtWidgets.QDirModel.fileName(index)¶
- Parameters:
index –
PySide2.QtCore.QModelIndex
- Return type:
str
Returns the name of the item stored in the model under the
index
given.
- PySide2.QtWidgets.QDirModel.filePath(index)¶
- Parameters:
index –
PySide2.QtCore.QModelIndex
- Return type:
str
Returns the path of the item stored in the model under the
index
given.
- PySide2.QtWidgets.QDirModel.filter()¶
- Return type:
Filters
Returns the filter specification for the directory model.
See also
setFilter()
Filters
- PySide2.QtWidgets.QDirModel.iconProvider()¶
- Return type:
Returns the file icon provider for this directory model.
See also
- PySide2.QtWidgets.QDirModel.index(path[, column=0])¶
- Parameters:
path – str
column – int
- Return type:
This is an overloaded function.
Returns the model item index for the given
path
.
- PySide2.QtWidgets.QDirModel.isDir(index)¶
- Parameters:
index –
PySide2.QtCore.QModelIndex
- Return type:
bool
Returns
true
if the model itemindex
represents a directory; otherwise returnsfalse
.
- PySide2.QtWidgets.QDirModel.isReadOnly()¶
- Return type:
bool
This property holds Whether the directory model allows writing to the file system.
If this property is set to false, the directory model will allow renaming, copying and deleting of files and directories.
This property is
true
by default
- PySide2.QtWidgets.QDirModel.lazyChildCount()¶
- Return type:
bool
This property holds Whether the directory model optimizes the
hasChildren
function to only check if the item is a directory..If this property is set to false, the directory model will make sure that a directory actually containes any files before reporting that it has children. Otherwise the directory model will report that an item has children if the item is a directory.
This property is
false
by default
- PySide2.QtWidgets.QDirModel.mkdir(parent, name)¶
- Parameters:
parent –
PySide2.QtCore.QModelIndex
name – str
- Return type:
Create a directory with the
name
in theparent
model item.
- PySide2.QtWidgets.QDirModel.nameFilters()¶
- Return type:
list of strings
Returns a list of filters applied to the names in the model.
See also
- PySide2.QtWidgets.QDirModel.refresh([parent=QModelIndex()])¶
- Parameters:
parent –
PySide2.QtCore.QModelIndex
QDirModel
caches file information. This function updates the cache. Theparent
parameter is the directory from which the model is updated; the default value will update the model from root directory of the file system (the entire model).
- PySide2.QtWidgets.QDirModel.remove(index)¶
- Parameters:
index –
PySide2.QtCore.QModelIndex
- Return type:
bool
Removes the model item
index
from the directory model and deletes the corresponding file from the file system , returning true if successful. If the item cannot be removed, false is returned.Warning
This function deletes files from the file system; it does not move them to a location where they can be recovered.
See also
- PySide2.QtWidgets.QDirModel.resolveSymlinks()¶
- Return type:
bool
This property holds Whether the directory model should resolve symbolic links.
This is only relevant on operating systems that support symbolic links.
- PySide2.QtWidgets.QDirModel.rmdir(index)¶
- Parameters:
index –
PySide2.QtCore.QModelIndex
- Return type:
bool
Removes the directory corresponding to the model item
index
in the directory model and deletes the corresponding directory from the file system , returning true if successful. If the directory cannot be removed, false is returned.Warning
This function deletes directories from the file system; it does not move them to a location where they can be recovered.
See also
- PySide2.QtWidgets.QDirModel.setFilter(filters)¶
- Parameters:
filters –
Filters
Sets the directory model’s filter to that specified by
filters
.Note that the filter you set should always include the
AllDirs
enum value, otherwiseQDirModel
won’t be able to read the directory structure.See also
filter()
Filters
- PySide2.QtWidgets.QDirModel.setIconProvider(provider)¶
- Parameters:
provider –
PySide2.QtWidgets.QFileIconProvider
Sets the
provider
of file icons for the directory model.See also
- PySide2.QtWidgets.QDirModel.setLazyChildCount(enable)¶
- Parameters:
enable – bool
This property holds Whether the directory model optimizes the
hasChildren
function to only check if the item is a directory..If this property is set to false, the directory model will make sure that a directory actually containes any files before reporting that it has children. Otherwise the directory model will report that an item has children if the item is a directory.
This property is
false
by default
- PySide2.QtWidgets.QDirModel.setNameFilters(filters)¶
- Parameters:
filters – list of strings
Sets the name
filters
for the directory model.See also
- PySide2.QtWidgets.QDirModel.setReadOnly(enable)¶
- Parameters:
enable – bool
This property holds Whether the directory model allows writing to the file system.
If this property is set to false, the directory model will allow renaming, copying and deleting of files and directories.
This property is
true
by default
- PySide2.QtWidgets.QDirModel.setResolveSymlinks(enable)¶
- Parameters:
enable – bool
This property holds Whether the directory model should resolve symbolic links.
This is only relevant on operating systems that support symbolic links.
- PySide2.QtWidgets.QDirModel.setSorting(sort)¶
- Parameters:
sort –
SortFlags
Sets the directory model’s sorting order to that specified by
sort
.See also
sorting()
SortFlags
- PySide2.QtWidgets.QDirModel.sorting()¶
- Return type:
SortFlags
Returns the sorting method used for the directory model.
See also
setSorting()
SortFlags
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.