gpt4 book ai didi

python - pyqt:向 QFileSystemModel 添加自定义列

转载 作者:行者123 更新时间:2023-11-28 22:53:08 25 4
gpt4 key购买 nike

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

最佳答案

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

关于python - pyqt:向 QFileSystemModel 添加自定义列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19690998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com