PyQt:QFileSystemModel复选框过滤器

时间:2016-11-06 05:05:41

标签: python pyqt filtering qfilesystemmodel

我正在尝试使用python / pyqt创建一个实用程序,从QFileSystemModel创建一个* .tar存档(仅包括那些已检查的项目)。现在我希望控制QFileSystemModel复选框以使用fileName / fileType / fileSize进行过滤。

如何在fileName / fileType / fileSize上使用通配符搜索检查/取消选中该类外的QFileSystemModel个复选框?

class CheckableDirModel(QtGui.QFileSystemModel):
    def __init__(self, parent=None):
        QtGui.QFileSystemModel.__init__(self, None)
        self.checks = {}

    def data(self, index, role=QtCore.Qt.DisplayRole):
        if role != QtCore.Qt.CheckStateRole:
            return QtGui.QFileSystemModel.data(self, index, role)
        else:
            if index.column() == 0:
                return self.checkState(index)

    def flags(self, index):
        return QtGui.QFileSystemModel.flags(self, index) | QtCore.Qt.ItemIsUserCheckable

    def checkState(self, index):
        if index in self.checks:
            return self.checks[index]
        else:
            return QtCore.Qt.Checked

    def setData(self, index, value, role):
        if (role == QtCore.Qt.CheckStateRole and index.column() == 0):
            self.checks[index] = value
            self.emit(QtCore.SIGNAL("dataChanged(QModelIndex,QModelIndex)"), index, index)
            return True 
        return QtGui.QFileSystemModel.setData(self, index, value, role)



    self.dirTreeView = QtGui.QTreeView(self.centralwidget)
    self.dirModel = CheckableDirModel()
    self.dirTreeView.setModel(self.dirModel)

See Snapshot of UI Here

0 个答案:

没有答案