2017-10-21 44 views
0

我使用QStandardItemModel維護QTreeView,以及如何修改或刪除下面圖像中的紅色圓圈。 謝謝。QTreeView和使用QStandardModel追加項目

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

回答

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) 
添加角色規則