QFileSystemModelclass provides a data model for the local filesystem. 更多 …
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
lastModified
(index)
def
mkdir
(parent, name)
def
myComputer
([role=Qt.DisplayRole])
def
nameFilterDisables
()
def
nameFilters
()
def
options
()
def
remove
(index)
def
resolveSymlinks
()
def
rmdir
(index)
def
rootDirectory
()
def
rootPath
()
def
setFilter
(filters)
def
setIconProvider
(provider)
def
setNameFilterDisables
(enable)
def
setNameFilters
(filters)
def
setOption
(option[, on=true])
def
setOptions
(options)
def
setReadOnly
(enable)
def
setResolveSymlinks
(enable)
def
setRootPath
(path)
def
size
(index)
def
testOption
(option)
def
type
(index)
def
directoryLoaded
(path)
def
fileRenamed
(path, oldName, newName)
def
rootPathChanged
(newPath)
此类提供对本地文件系统的访问,提供用于重命名 移除文件 目录及创建新目录的函数。在最简单情况下,它可以被用于适合的显示 Widget 作为浏览器 (或过滤器) 的一部分。
QFileSystemModelcan be accessed using the standard interface provided byQAbstractItemModel, but it also provides some convenience functions that are specific to a directory model. ThefileInfo(),isDir(),fileName()andfilePath()functions provide information about the underlying files and directories related to items in the model. Directories can be created and removed usingmkdir(),rmdir().注意
QFileSystemModelrequires an instance ofQApplication.
A directory model that displays the contents of a default directory is usually constructed with a parent object:
model = QFileSystemModel() model.setRootPath(QDir.currentPath())树视图可用于显示模型的内容
tree = QTreeView() tree.setModel(model)and the contents of a particular directory can be displayed by setting the tree view’s root index:
tree.setRootIndex(model.index(QDir.currentPath()))The view’s root index can be used to control how much of a hierarchical model is displayed.
QFileSystemModelprovides a convenience function that returns a suitable model index for a path to a directory within the model.
QFileSystemModelwill not fetch any files or directories untilsetRootPath()is called. This will prevent any unnecessary querying on the file system until that point such as listing the drives on Windows.不像
QDirModel,QFileSystemModeluses a separate thread to populate itself so it will not cause the main thread to hang as the file system is being queried. Calls torowCount()will return 0 until the model populates a directory.
QFileSystemModelkeeps a cache with file information. The cache is automatically kept up to date using theQFileSystemWatcher.另请参阅
QFileSystemModel
(
[
parent=None
]
)
¶
- param parent
QObject
构造文件系统模型采用给定
parent
.
PySide2.QtWidgets.QFileSystemModel.
Roles
¶
|
常量 |
描述 |
|---|---|
|
QFileSystemModel.FileIconRole |
|
|
QFileSystemModel.FilePathRole |
|
|
QFileSystemModel.FileNameRole |
|
|
QFileSystemModel.FilePermissions |
PySide2.QtWidgets.QFileSystemModel.
Option
¶
|
常量 |
描述 |
|---|---|
|
QFileSystemModel.DontWatchForChanges |
Do not add file watchers to the paths. This reduces overhead when using the model for simple tasks like line edit completion. |
|
QFileSystemModel.DontResolveSymlinks |
Don’t resolve symlinks in the file system model. By default, symlinks are resolved. |
|
QFileSystemModel.DontUseCustomDirectoryIcons |
Always use the default directory icon. Some platforms allow the user to set a different icon. Custom icon lookup causes a big performance impact over network or removable drives. This sets the
|
另请参阅
New in version 5.14.
PySide2.QtWidgets.QFileSystemModel.
directoryLoaded
(
path
)
¶
path – unicode
PySide2.QtWidgets.QFileSystemModel.
fileIcon
(
index
)
¶
index
–
QModelIndex
QIcon
Returns the icon for the item stored in the model under the given
index
.
PySide2.QtWidgets.QFileSystemModel.
fileInfo
(
index
)
¶
index
–
QModelIndex
QFileInfo
返回
QFileInfo
for the item stored in the model under the given
index
.
PySide2.QtWidgets.QFileSystemModel.
fileName
(
index
)
¶
index
–
QModelIndex
unicode
Returns the file name for the item stored in the model under the given
index
.
PySide2.QtWidgets.QFileSystemModel.
filePath
(
index
)
¶
index
–
QModelIndex
unicode
Returns the path of the item stored in the model under the
index
给定。
PySide2.QtWidgets.QFileSystemModel.
fileRenamed
(
path
,
oldName
,
newName
)
¶
path – unicode
oldName – unicode
newName – unicode
PySide2.QtWidgets.QFileSystemModel.
filter
(
)
¶
过滤器
Returns the filter specified for the directory model.
If a filter has not been set, the default filter is
AllEntries
|
NoDotAndDotDot
|
AllDirs
.
另请参阅
setFilter()
过滤器
PySide2.QtWidgets.QFileSystemModel.
iconProvider
(
)
¶
Returns the file icon provider for this directory model.
另请参阅
PySide2.QtWidgets.QFileSystemModel.
index
(
path
[
,
column=0
]
)
¶
path – unicode
column
–
int
QModelIndex
这是重载函数。
Returns the model item index for the given
path
and
column
.
PySide2.QtWidgets.QFileSystemModel.
isDir
(
index
)
¶
index
–
QModelIndex
bool
返回
true
若模型项
index
represents a directory; otherwise returns
false
.
PySide2.QtWidgets.QFileSystemModel.
isReadOnly
(
)
¶
bool
PySide2.QtWidgets.QFileSystemModel.
lastModified
(
index
)
¶
index
–
QModelIndex
QDateTime
Returns the date and time when
index
was last modified.
PySide2.QtWidgets.QFileSystemModel.
mkdir
(
parent
,
name
)
¶
parent
–
QModelIndex
name – unicode
QModelIndex
Create a directory with the
name
在
parent
model index.
PySide2.QtWidgets.QFileSystemModel.
myComputer
(
[
role=Qt.DisplayRole
]
)
¶
role
–
int
object
Returns the data stored under the given
role
for the item “My Computer”.
另请参阅
ItemDataRole
PySide2.QtWidgets.QFileSystemModel.
nameFilterDisables
(
)
¶
bool
PySide2.QtWidgets.QFileSystemModel.
nameFilters
(
)
¶
字符串列表
Returns a list of filters applied to the names in the model.
另请参阅
PySide2.QtWidgets.QFileSystemModel.
options
(
)
¶
Options
另请参阅
PySide2.QtWidgets.QFileSystemModel.
remove
(
index
)
¶
index
–
QModelIndex
bool
Removes the model item
index
from the file system 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.QFileSystemModel.
resolveSymlinks
(
)
¶
bool
另请参阅
PySide2.QtWidgets.QFileSystemModel.
rmdir
(
index
)
¶
index
–
QModelIndex
bool
Removes the directory corresponding to the model item
index
in the file system 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.QFileSystemModel.
rootDirectory
(
)
¶
QDir
The currently set directory
另请参阅
PySide2.QtWidgets.QFileSystemModel.
rootPath
(
)
¶
unicode
The currently set root path
PySide2.QtWidgets.QFileSystemModel.
rootPathChanged
(
newPath
)
¶
newPath – unicode
PySide2.QtWidgets.QFileSystemModel.
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
QFileSystemModel
won’t be able to read the directory structure.
另请参阅
filter()
过滤器
PySide2.QtWidgets.QFileSystemModel.
setIconProvider
(
provider
)
¶
provider
–
QFileIconProvider
设置
provider
of file icons for the directory model.
另请参阅
PySide2.QtWidgets.QFileSystemModel.
setNameFilterDisables
(
enable
)
¶
enable
–
bool
另请参阅
PySide2.QtWidgets.QFileSystemModel.
setNameFilters
(
filters
)
¶
filters – 字符串列表
Sets the name
filters
to apply against the existing files.
另请参阅
PySide2.QtWidgets.QFileSystemModel.
setOption
(
option
[
,
on=true
]
)
¶
option
–
Option
on
–
bool
设置给定
option
to be enabled if
on
is true; otherwise, clears the given
option
.
选项应被设置,在更改特性之前。
另请参阅
options
testOption()
PySide2.QtWidgets.QFileSystemModel.
setReadOnly
(
enable
)
¶
enable
–
bool
另请参阅
PySide2.QtWidgets.QFileSystemModel.
setResolveSymlinks
(
enable
)
¶
enable
–
bool
另请参阅
PySide2.QtWidgets.QFileSystemModel.
setRootPath
(
path
)
¶
path – unicode
QModelIndex
Sets the directory that is being watched by the model to
newPath
by installing a
file
system
watcher
on it. Any changes to files and directories within this directory will be reflected in the model.
If the path is changed, the
rootPathChanged()
signal will be emitted.
注意
This function does not change the structure of the model or modify the data available to views. In other words, the “root” of the model is
not
changed to include only files and directories within the directory specified by
newPath
in the file system.
另请参阅
PySide2.QtWidgets.QFileSystemModel.
size
(
index
)
¶
index
–
QModelIndex
qint64
Returns the size in bytes of
index
. If the file does not exist, 0 is returned.
PySide2.QtWidgets.QFileSystemModel.
testOption
(
option
)
¶
option
–
Option
bool
返回
true
若给定
option
被启用;否则,返回 false。
另请参阅
options
setOption()
PySide2.QtWidgets.QFileSystemModel.
type
(
index
)
¶
index
–
QModelIndex
unicode
Returns the type of file
index
such as “Directory” or “JPEG file”.