【问题标题】:How do I change the title of the tree view that is created如何更改创建的树视图的标题
【发布时间】:2011-07-13 11:29:25
【问题描述】:

我创建了一个带有复选框的基本树视图,下面是代码:

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。如何更改标题?任何帮助都非常感谢?

【问题讨论】:

    标签: python pyqt checkbox qcombobox


    【解决方案1】:

    尝试以下方法:

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

    显然你可以使用任何你喜欢的文字。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-01
      • 1970-01-01
      • 2021-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-29
      相关资源
      最近更新 更多