• PySide 模块
  • PySide.QtGui
  • 内容表

    上一话题

    QItemSelectionModel

    下一话题

    QAbstractProxyModel

    QDirModel

    概要

    函数

    详细描述

    PySide.QtGui.QDirModel class provides a data model for the local filesystem.

    The usage of PySide.QtGui.QDirModel is not recommended anymore. The PySide.QtGui.QFileSystemModel 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.

    PySide.QtGui.QDirModel keeps a cache with file information. The cache needs to be updated with PySide.QtGui.QDirModel.refresh() .

    PySide.QtGui.QDirModel can be accessed using the standard interface provided by PySide.QtCore.QAbstractItemModel , but it also provides some convenience functions that are specific to a directory model. The PySide.QtGui.QDirModel.fileInfo() and PySide.QtGui.QDirModel.isDir() functions provide information about the underlying files and directories related to items in the model.

    Directories can be created and removed using PySide.QtGui.QDirModel.mkdir() , PySide.QtGui.QDirModel.rmdir() , and the model will be automatically updated to take the changes into account.

    注意

    PySide.QtGui.QDirModel requires an instance of a GUI application.

    class PySide.QtGui. QDirModel ( [ parent=None ] )
    class PySide.QtGui. QDirModel ( nameFilters , filters , sort [ , parent=None ] )
    参数:
    • parent PySide.QtCore.QObject
    • nameFilters – list of strings
    • sort PySide.QtCore.QDir.SortFlags
    • filters PySide.QtCore.QDir.Filters

    Constructs a directory model with the given parent .

    PySide.QtGui.QDirModel. Roles
    常量 描述
    QDirModel.FileIconRole  
    QDirModel.FilePathRole  
    QDirModel.FileNameRole  
    PySide.QtGui.QDirModel. fileIcon ( index )
    参数: index PySide.QtCore.QModelIndex
    返回类型: PySide.QtGui.QIcon

    Returns the icons for the item stored in the model under the given index .

    PySide.QtGui.QDirModel. fileInfo ( index )
    参数: index PySide.QtCore.QModelIndex
    返回类型: PySide.QtCore.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 PySide.QtGui.QDirModel.resolveSymlinks() is enabled or not.

    另请参阅

    QFileInfo.symLinkTarget()

    PySide.QtGui.QDirModel. fileName ( index )
    参数: index PySide.QtCore.QModelIndex
    返回类型: unicode

    Returns the name of the item stored in the model under the index 给定。

    PySide.QtGui.QDirModel. filePath ( index )
    参数: index PySide.QtCore.QModelIndex
    返回类型: unicode

    Returns the path of the item stored in the model under the index 给定。

    PySide.QtGui.QDirModel. filter ( )
    返回类型: PySide.QtCore.QDir.Filters

    Returns the filter specification for the directory model.

    另请参阅

    PySide.QtGui.QDirModel.setFilter() QDir.Filters

    PySide.QtGui.QDirModel. iconProvider ( )
    返回类型: PySide.QtGui.QFileIconProvider

    Returns the file icon provider for this directory model.

    PySide.QtGui.QDirModel. index ( path [ , column=0 ] )
    参数:
    • path – unicode
    • column PySide.QtCore.int
    返回类型:

    PySide.QtCore.QModelIndex

    这是重载函数。

    Returns the model item index for the given path .

    PySide.QtGui.QDirModel. isDir ( index )
    参数: index PySide.QtCore.QModelIndex
    返回类型: PySide.QtCore.bool

    Returns true if the model item index represents a directory; otherwise returns false.

    PySide.QtGui.QDirModel. isReadOnly ( )
    返回类型: PySide.QtCore.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

    PySide.QtGui.QDirModel. lazyChildCount ( )
    返回类型: PySide.QtCore.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

    PySide.QtGui.QDirModel. mkdir ( parent , name )
    参数:
    返回类型:

    PySide.QtCore.QModelIndex

    Create a directory with the name parent model item.

    PySide.QtGui.QDirModel. nameFilters ( )
    返回类型: 字符串列表

    Returns a list of filters applied to the names in the model.

    PySide.QtGui.QDirModel. refresh ( [ parent=QModelIndex() ] )
    参数: parent PySide.QtCore.QModelIndex

    PySide.QtGui.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).

    PySide.QtGui.QDirModel. remove ( index )
    参数: index PySide.QtCore.QModelIndex
    返回类型: PySide.QtCore.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.

    返回类型: PySide.QtCore.bool

    This property holds Whether the directory model should resolve symbolic links.

    This is only relevant on operating systems that support symbolic links.

    PySide.QtGui.QDirModel. rmdir ( index )
    参数: index PySide.QtCore.QModelIndex
    返回类型: PySide.QtCore.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.

    PySide.QtGui.QDirModel. setFilter ( filters )
    参数: filters PySide.QtCore.QDir.Filters
    PySide.QtGui.QDirModel. setIconProvider ( provider )
    参数: provider PySide.QtGui.QFileIconProvider

    设置 provider of file icons for the directory model.

    PySide.QtGui.QDirModel. setLazyChildCount ( enable )
    参数: enable PySide.QtCore.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

    PySide.QtGui.QDirModel. setNameFilters ( filters )
    参数: filters – list of strings

    Sets the name filters for the directory model.

    PySide.QtGui.QDirModel. setReadOnly ( enable )
    参数: enable PySide.QtCore.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

    参数: enable PySide.QtCore.bool

    This property holds Whether the directory model should resolve symbolic links.

    This is only relevant on operating systems that support symbolic links.

    PySide.QtGui.QDirModel. setSorting ( sort )
    参数: sort PySide.QtCore.QDir.SortFlags
    PySide.QtGui.QDirModel. sorting ( )
    返回类型: PySide.QtCore.QDir.SortFlags

    Returns the sorting method used for the directory model.

    另请参阅

    PySide.QtGui.QDirModel.setSorting() QDir.SortFlags