QTreeView 和使用 QStandardModel 追加项目
QTreeView and using QStandardModel to append items
我使用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]
我找到了 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)
我使用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]
我找到了 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)