0

I have created a basic treeview with checkboxes and below is the code:

class StdItemModel(QStandardItemModel):
def __init__(self, parent = None):
    super(StdItemModel, self).__init__(parent)

class CheckBoxTreeView(QTreeView):
    def __init__(self, parent = None):
        super(CheckBoxTreeView, self).__init__(parent)
        self.mylist = ['STB1','STB2','STB3','STB4','STB5','STB6','STB7','STB8']
        self.MainUI()

def MainUI(self):
    self.stdmodel = StdItemModel()
    for val in self.mylist:
        item = QStandardItem(val)
        item.setCheckable(True)
        self.stdmodel.appendRow([item])        
    self.setModel(self.stdmodel) # Add Elements

When I run this code, the tree view with checkbox is displayed, but the title is set to 1. How do I change the title? Any help is highly appreciated?

4

1 回答 1

0

尝试以下操作:

title = "This is my title, there are many like it but this one is mine..." self.headerItem().setText(0, title)

显然,您可以使用任何您喜欢的文本。

于 2011-03-11T14:34:20.050 回答