QTreeView并使用QStandardModel追加项目

时间:2017-10-21 13:33:31

标签: python qstandarditemmodel pyside2

我使用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]

no

1 个答案:

答案 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)