【问题标题】:pyqt: Adding a custom column to QFileSystemModelpyqt:向 QFileSystemModel 添加自定义列
【发布时间】:2013-11-10 13:01:38
【问题描述】:

我需要向 QFileSystemModel 添加一个额外的列。我在以下位置看到了答案:QT - adding own column to QFileSystemModel
有人能告诉我如何在 pyqt4 中正确定义子类吗?

【问题讨论】:

    标签: python qt user-interface pyqt


    【解决方案1】:

    您几乎可以复制粘贴 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-11
      • 1970-01-01
      • 1970-01-01
      • 2015-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-05
      相关资源
      最近更新 更多