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
()
The usage of
QDirModelis not recommended anymore. TheQFileSystemModelclass 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.
QDirModelkeeps a cache with file information. The cache needs to be updated withrefresh().
QDirModelcan 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.注意
QDirModelrequires an instance ofQApplication.
QDirModel
(
[
parent=None
]
)
¶
注意
This constructor is deprecated.
QDirModel(nameFilters, filters, sort[, parent=None])
注意
This constructor is deprecated.
- param parent
QObject- param nameFilters
字符串列表
- param 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 the
nameFilters
和
filters
are included in the model. The sort order is given by the
sort
flags.
PySide2.QtWidgets.QDirModel.
Roles
¶
|
常量 |
描述 |
|---|---|
|
QDirModel.FileIconRole |
|
|
QDirModel.FilePathRole |
|
|
QDirModel.FileNameRole |
PySide2.QtWidgets.QDirModel.
fileIcon
(
index
)
¶
index
–
QModelIndex
QIcon
Returns the icons for the item stored in the model under the given
index
.
PySide2.QtWidgets.QDirModel.
fileInfo
(
index
)
¶
index
–
QModelIndex
QFileInfo
Returns the file information for the specified model
index
.
注意
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.
另请参阅
symLinkTarget()
PySide2.QtWidgets.QDirModel.
fileName
(
index
)
¶
index
–
QModelIndex
unicode
Returns the name of the item stored in the model under the
index
给定。
PySide2.QtWidgets.QDirModel.
filePath
(
index
)
¶
index
–
QModelIndex
unicode
Returns the path of the item stored in the model under the
index
给定。
PySide2.QtWidgets.QDirModel.
filter
(
)
¶
过滤器
Returns the filter specification for the directory model.
另请参阅
setFilter()
过滤器
PySide2.QtWidgets.QDirModel.
iconProvider
(
)
¶
Returns the file icon provider for this directory model.
另请参阅
PySide2.QtWidgets.QDirModel.
index
(
path
[
,
column=0
]
)
¶
path – unicode
column
–
int
QModelIndex
这是重载函数。
Returns the model item index for the given
path
.
PySide2.QtWidgets.QDirModel.
isDir
(
index
)
¶
index
–
QModelIndex
bool
返回
true
若模型项
index
represents a directory; otherwise returns
false
.
PySide2.QtWidgets.QDirModel.
isReadOnly
(
)
¶
bool
PySide2.QtWidgets.QDirModel.
lazyChildCount
(
)
¶
bool
另请参阅
PySide2.QtWidgets.QDirModel.
mkdir
(
parent
,
name
)
¶
parent
–
QModelIndex
name – unicode
QModelIndex
Create a directory with the
name
在
parent
model item.
PySide2.QtWidgets.QDirModel.
nameFilters
(
)
¶
字符串列表
Returns a list of filters applied to the names in the model.
另请参阅
PySide2.QtWidgets.QDirModel.
refresh
(
[
parent=QModelIndex()
]
)
¶
parent
–
QModelIndex
QDirModel
caches file information. This function updates the cache. The
parent
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
)
¶
index
–
QModelIndex
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.
警告
This function deletes files from the file system; it does not move them to a location where they can be recovered.
另请参阅
PySide2.QtWidgets.QDirModel.
resolveSymlinks
(
)
¶
bool
另请参阅
PySide2.QtWidgets.QDirModel.
rmdir
(
index
)
¶
index
–
QModelIndex
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.
警告
This function deletes directories from the file system; it does not move them to a location where they can be recovered.
另请参阅
PySide2.QtWidgets.QDirModel.
setFilter
(
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, otherwise
QDirModel
won’t be able to read the directory structure.
另请参阅
filter()
过滤器
PySide2.QtWidgets.QDirModel.
setIconProvider
(
provider
)
¶
provider
–
QFileIconProvider
设置
provider
of file icons for the directory model.
另请参阅
PySide2.QtWidgets.QDirModel.
setLazyChildCount
(
enable
)
¶
enable
–
bool
另请参阅
PySide2.QtWidgets.QDirModel.
setNameFilters
(
filters
)
¶
filters – 字符串列表
Sets the name
filters
for the directory model.
另请参阅
PySide2.QtWidgets.QDirModel.
setReadOnly
(
enable
)
¶
enable
–
bool
另请参阅
PySide2.QtWidgets.QDirModel.
setResolveSymlinks
(
enable
)
¶
enable
–
bool
另请参阅
PySide2.QtWidgets.QDirModel.
setSorting
(
sort
)
¶
sort
–
SortFlags
Sets the directory model’s sorting order to that specified by
sort
.
另请参阅
sorting()
SortFlags
PySide2.QtWidgets.QDirModel.
sorting
(
)
¶
SortFlags
Returns the sorting method used for the directory model.
另请参阅
setSorting()
SortFlags