我创建了一个带有复选框的基本树视图,下面是代码:
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
当我运行此代码时,会显示带有复选框的树视图,但标题设置为1.如何更改标题?任何帮助都非常感谢?
答案 0 :(得分:0)
尝试以下内容:
title = "This is my title, there are many like it but this one is mine..."
self.headerItem().setText(0, title)
显然你可以使用你喜欢的任何文字。