QFileSystemModel Class Reference
[QtGui module]
该QFileSystemModel类提供了在本地文件系统的数据模型。More…
Types
enum Roles { FileIconRole, FilePathRole, FileNameRole, FilePermissions }
Methods
__init__ (self, QObject parent = None)
bool canFetchMore (self, QModelIndex parent)
int columnCount (self, QModelIndex parent = QModelIndex())
QVariant data (self, QModelIndex index, int role = Qt.DisplayRole)
bool dropMimeData (self, QMimeData data, Qt.DropAction action, int row, int column, QModelIndex parent)
bool event (self, QEvent event)
fetchMore (self, QModelIndex parent)
QIcon fileIcon (self, QModelIndex aindex)
QFileInfo fileInfo (self, QModelIndex aindex)
QString fileName (self, QModelIndex aindex)
QString filePath (self, QModelIndex index)
QDir.Filters filter (self)
Qt.ItemFlags flags (self, QModelIndex index)
bool hasChildren (self, QModelIndex parent = QModelIndex())
QVariant headerData (self, int section, Qt.Orientation orientation, int role = Qt.DisplayRole)
QFileIconProvider iconProvider (self)
QModelIndex index (self, int row, int column, QModelIndex parent = QModelIndex())
QModelIndex index (self, QString path, int column = 0)
bool isDir (self, QModelIndex index)
bool isReadOnly (self)
QDateTime lastModified (self, QModelIndex index)
QMimeData mimeData (self, list-of-QModelIndex indexes)
QStringList mimeTypes (self)
QModelIndex mkdir (self, QModelIndex parent, QString name)
QVariant myComputer (self, int role = Qt.DisplayRole)
bool nameFilterDisables (self)
QStringList nameFilters (self)
QModelIndex parent (self, QModelIndex child)
QFile.Permissions permissions (self, QModelIndex index)
bool remove (self, QModelIndex aindex)
bool resolveSymlinks (self)
bool rmdir (self, QModelIndex aindex)
QDir rootDirectory (self)
QString rootPath (self)
int rowCount (self, QModelIndex parent = QModelIndex())
bool setData (self, QModelIndex idx, QVariant value, int role = Qt.EditRole)
setFilter (self, QDir.Filters filters)
setIconProvider (self, QFileIconProvider provider)
setNameFilterDisables (self, bool enable)
setNameFilters (self, QStringList filters)
setReadOnly (self, bool enable)
setResolveSymlinks (self, bool enable)
QModelIndex setRootPath (self, QString path)
int size (self, QModelIndex index)
sort (self, int column, Qt.SortOrder order = Qt.AscendingOrder)
Qt.DropActions supportedDropActions (self)
timerEvent (self, QTimerEvent event)
QString type (self, QModelIndex index)
Qt Signals
void directoryLoaded (const QString&)
void fileRenamed (const QString&,const QString&,const QString&)
void rootPathChanged (const QString&)
Detailed Description
该QFileSystemModel类提供了在本地文件系统的数据模型。
这个类提供了访问本地文件系统,提供了功能重命名和删除文件和目录,并创建新的目录。在最简单的情况下,它可以用于与合适的显示部件作为一个浏览器或过滤器的一部分。
QFileSystemModel可以使用所提供的标准接口来访问QAbstractItemModel的,但它也提供了一些方便的功能所特有的一个目录模型。该fileInfo( )isDir( )name( )和路径( )函数提供了有关与模型中的项目相关的文件和目录信息。目录中可以创建和删除使用mkdir( )rmdir( ) 。
Note:QFileSystemModel需要一个GUI应用程序的一个实例。
Example Usage
通常是构造一个父对象,显示一个默认目录中的内容的目录型号:
QFileSystemModel *model = new QFileSystemModel;
model->setRootPath([QDir]($docs-qdir.html).currentPath());
树视图可用于显示模型的内容
[QTreeView](qtreeview.html) *tree = new [QTreeView](qtreeview.html)(splitter);
tree->setModel(model);
和一个特定的目录中的内容可以显示通过将树视图的根指数:
tree->setRootIndex(model->index([QDir]($docs-qdir.html).currentPath()));
视图的根指数,可用于控制如何分层模型的多显示。QDirModel(obsolete)提供了一个方便的功能,用于返回一个路径模型中的一个目录一个合适的模型索引。
Caching and Performance
QFileSystemModel不会获取任何文件或目录,直到setRootPath()被调用。这将防止在文件系统上的任何不必要的查询,直到这一点,如清单上的Windows的驱动器。
不像QDirModel(obsolete), QFileSystemModel使用单独的线程来填充自身,所以它不会造成主线程挂起的文件系统受到质疑。调用rowCount( )将返回0 ,直到模型填充的目录。
QFileSystemModel保持与文件信息的高速缓存。高速缓存是使用自动保持更新的QFileSystemWatcher。
Type Documentation
QFileSystemModel.Roles
Constant | Value |
---|---|
QFileSystemModel.FileIconRole |
Qt.DecorationRole |
QFileSystemModel.FilePathRole |
Qt.UserRole + 1 |
QFileSystemModel.FileNameRole |
Qt.UserRole + 2 |
QFileSystemModel.FilePermissions |
Qt.UserRole + 3 |
Method Documentation
QFileSystemModel.__init__ (self, QObject parent = None)
该parent的说法,如果不是没有,原因self通过Qt的,而不是PyQt的拥有。
构造一个文件系统模型与给定的parent。
bool QFileSystemModel.canFetchMore (self, QModelIndex parent)
从重新实现QAbstractItemModel.canFetchMore( ) 。
int QFileSystemModel.columnCount (self, QModelIndex parent = QModelIndex())
从重新实现QAbstractItemModel.columnCount( ) 。
QVariant QFileSystemModel.data (self, QModelIndex index, int role = Qt.DisplayRole)
从重新实现QAbstractItemModel.data( ) 。
See also setData( ) 。
bool QFileSystemModel.dropMimeData (self, QMimeData data, Qt.DropAction action, int row, int column, QModelIndex parent)
从重新实现QAbstractItemModel.dropMimeData( ) 。
处理data通过拖放操作,与给定的供给结束action过在由指定的模型中的行row和column以及由parent索引。
See also supportedDropActions( ) 。
bool QFileSystemModel.event (self, QEvent event)
从重新实现QObject.event( ) 。
QFileSystemModel.fetchMore (self, QModelIndex parent)
从重新实现QAbstractItemModel.fetchMore( ) 。
QIcon QFileSystemModel.fileIcon (self, QModelIndex aindex)
[
根据给定的返回存储在模型中的项的图标index。
](qicon.html)
QFileInfo QFileSystemModel.fileInfo (self, QModelIndex aindex)
返回QFileInfo根据给定的存储在模型中的项index。
QString QFileSystemModel.fileName (self, QModelIndex aindex)
返回根据给定的存储在模型中的项目的文件名index。
QString QFileSystemModel.filePath (self, QModelIndex index)
返回根据存储在模型中的项的路径index给出。
QDir.Filters QFileSystemModel.filter (self)
[
返回目录模型中指定的过滤器。
]($docs-index.htm)
如果一个过滤器没有被设置,则默认过滤器是QDir.AllEntries|QDir.NoDotAndDotDot|QDir.AllDirs。
See also setFilter()和QDir.Filters。
Qt.ItemFlags QFileSystemModel.flags (self, QModelIndex index)
从重新实现QAbstractItemModel.flags( ) 。
bool QFileSystemModel.hasChildren (self, QModelIndex parent = QModelIndex())
从重新实现QAbstractItemModel.hasChildren( ) 。
QVariant QFileSystemModel.headerData (self, int section, Qt.Orientation orientation, int role = Qt.DisplayRole)
从重新实现QAbstractItemModel.headerData( ) 。
QFileIconProvider QFileSystemModel.iconProvider (self)
[
返回文件的图标提供商此目录的模式。
]($docs-qfileiconprovider.html)
See also setIconProvider( ) 。
QModelIndex QFileSystemModel.index (self, int row, int column, QModelIndex parent = QModelIndex())
从重新实现QAbstractItemModel.index( ) 。
QModelIndex QFileSystemModel.index (self, QString path, int column = 0)
[
这是一个重载函数。
返回模型项指数为给定的path和column。
bool QFileSystemModel.isDir (self, QModelIndex index)
返回True如果模型项目index表示一个目录,否则返回False 。
bool QFileSystemModel.isReadOnly (self)
]($docs-qmodelindex.html)
QDateTime QFileSystemModel.lastModified (self, QModelIndex index)
[
返回的日期和时间时index最后修订。
](qdatetime.html)
QMimeData QFileSystemModel.mimeData (self, list-of-QModelIndex indexes)
从重新实现QAbstractItemModel.mimeData( ) 。
返回一个对象,该对象包含指定的序列化描述indexes。用于描述对应于该索引的项的格式是从所获得的mimeTypes()函数。
如果索引的列表为空,则返回0 ,而不是一个序列化的空单。
QStringList QFileSystemModel.mimeTypes (self)
从重新实现QAbstractItemModel.mimeTypes( ) 。
返回可用于描述在模型中的项列表的MIME类型的列表。
QModelIndex QFileSystemModel.mkdir (self, QModelIndex parent, QString name)
[
创建具有一个目录name在parent模型索引。
QVariant QFileSystemModel.myComputer (self, int role = Qt.DisplayRole)
返回下指定存储的数据role该项目“我的电脑” 。
]($docs-qmodelindex.html)
bool QFileSystemModel.nameFilterDisables (self)
QStringList QFileSystemModel.nameFilters (self)
返回应用到该模型中的名称的过滤器列表。
See also setNameFilters( ) 。
QModelIndex QFileSystemModel.parent (self, QModelIndex child)
从重新实现QAbstractItemModel.parent( ) 。
QFile.Permissions QFileSystemModel.permissions (self, QModelIndex index)
返回的完整或的结果组合在一起QFile.Permission为index。
bool QFileSystemModel.remove (self, QModelIndex aindex)
删除模型项目index从文件系统模型和deletes the corresponding file from the file system,返回True,如果成功的。如果该项目不能被删除,则返回False。
Warning:此函数删除从文件系统中的文件,它not它们移动到那里他们可以恢复的位置。
See also rmdir( ) 。
bool QFileSystemModel.resolveSymlinks (self)
bool QFileSystemModel.rmdir (self, QModelIndex aindex)
删除对应的模型项目的目录index在文件系统模型和deletes the corresponding directory from the file system,返回True,如果成功的。如果目录不能被删除,则返回False。
Warning:此函数删除目录的文件系统;它not它们移动到那里他们可以恢复的位置。
See also remove( ) 。
QDir QFileSystemModel.rootDirectory (self)
[
当前设置的目录
]($docs-qdir.html)
QString QFileSystemModel.rootPath (self)
当前设置的根路径
See also setRootPath()和rootDirectory( ) 。
int QFileSystemModel.rowCount (self, QModelIndex parent = QModelIndex())
从重新实现QAbstractItemModel.rowCount( ) 。
bool QFileSystemModel.setData (self, QModelIndex idx, QVariant value, int role = Qt.EditRole)
从重新实现QAbstractItemModel.setData( ) 。
See also data( ) 。
QFileSystemModel.setFilter (self, QDir.Filters filters)
设置目录型号的过滤器,通过指定filters。
请注意,您设置的过滤器应始终包含QDir.AllDirs枚举值,否则QFileSystemModel将无法读取的目录结构。
See also filter()和QDir.Filters。
QFileSystemModel.setIconProvider (self, QFileIconProvider provider)
设置provider文件图标的目录模式。
See also iconProvider( ) 。
QFileSystemModel.setNameFilterDisables (self, bool enable)
QFileSystemModel.setNameFilters (self, QStringList filters)
设置名称filters应用对现有的文件。
See also nameFilters( ) 。
QFileSystemModel.setReadOnly (self, bool enable)
QFileSystemModel.setResolveSymlinks (self, bool enable)
QModelIndex QFileSystemModel.setRootPath (self, QString path)
设置被观看了该模型的目录newPath通过安装file system watcher就可以了。任何更改的文件和该目录下的目录将反映在模型中。
如果该路径被改变,rootPathChanged()信号将被发射。
Note:此函数不改变模型的结构或修改提供给视图的数据。换句话说,本模型的“根”是not更改为包含所指定的目录中唯一的文件和目录newPath在文件系统中。
See also rootPath( ) 。
int QFileSystemModel.size (self, QModelIndex index)
返回该尺寸中的字节index。如果文件不存在,则返回0 。
QFileSystemModel.sort (self, int column, Qt.SortOrder order = Qt.AscendingOrder)
从重新实现QAbstractItemModel.sort( ) 。
Qt.DropActions QFileSystemModel.supportedDropActions (self)
从重新实现QAbstractItemModel.supportedDropActions( ) 。
QFileSystemModel.timerEvent (self, QTimerEvent event)
从重新实现QObject.timerEvent( ) 。
QString QFileSystemModel.type (self, QModelIndex index)
返回文件的类型index如“目录”或“ JPEG文件” 。
Qt Signal Documentation
void directoryLoaded (const QString&)
这是该信号的默认超载。
当采集线程完成加载这个信号被发射的path。
此功能被引入Qt的4.7 。
void fileRenamed (const QString&,const QString&,const QString&)
这是该信号的默认超载。
这个信号被发射时与一个文件oldName成功更名为newName。该文件位于目录path。
void rootPathChanged (const QString&)
这是该信号的默认超载。
这个信号被发射时的根路径已被更改为一个newPath。