我使用QStandardItemModel维护QTreeView,如何修改或删除下图中的红圈。 感谢。
from PySide2 import QtCore,QtGui
from PySide2.QtGui import QStandardItemModel
import pandas as pd
class PrjTreeModel(QStandardItemModel):
def __init__(self, parent=None):
super(PrjTreeModel, self).__init__(parent)
# self.items = data
self.itmes = pd.DataFrame([['Hello','@TFF']],columns=['UserId','ProjectId'])
self.refreshItems()
def refreshItems(self):
prjId = self.itmes['ProjectId']
child = ['RR','BB']
for i,row in prjId.iteritems():
parent = QtGui.QStandardItem(row)
child1 = QtGui.QStandardItem(child[0])
child2 = QtGui.QStandardItem(child[1])
parent.appendRow(child1)
parent.appendRow(child2)
self.appendRow(parent)
# def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole):
# return self.itmes['UserId'][0]
答案 0 :(得分:0)
我找到了api ......
我应该添加此代码。
treeview.header().hide()
如果我想修改标题,我应该在headerData
中添加角色规则if (role == QtCore.Qt.DisplayRole) and (orientation == QtCore.Qt.Horizontal) and (self.items is not None):
return self.items['UserId'][0]
else:
return QStandardItemModel.headerData(self, section, orientation, role)