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 に答える