pyqt:向QFileSystemModel添加自定义列

时间:2013-10-30 18:27:45

标签: python qt user-interface pyqt

我需要在QFileSystemModel中添加一个额外的列。我在QT - adding own column to QFileSystemModel发现了答案 有人会告诉我如何在pyqt4中正确定义子类吗?

1 个答案:

答案 0 :(得分:3)

您几乎可以复制粘贴C ++代码。这是pyqt实现:

class YourSystemModel(QtGui.QFileSystemModel):

    def columnCount(self, parent = QtCore.QModelIndex()):
        return super(YourSystemModel, self).columnCount()+1

    def data(self, index, role):
        if index.column() == self.columnCount() - 1:
            if role == QtCore.Qt.DisplayRole:
                return QtCore.QString("YourText")
            if role == QtCore.Qt.TextAlignmentRole:
                return QtCore.Qt.AlignHCenter

        return super(YourSystemModel, self).data(index, role)