我正在尝试使用 QStandardItemModel 来表示数据的层次结构,但是当我将 QStandardItems 添加到模型中时,我必须将它们分配到对象成员变量中,否则对象似乎已被删除。
例如
self.tree_model = QStandardItemModel()
self.tree_model.setHorizontalHeaderLabels(['Category'])
self.out_insertions = QStandardItem("Insertions")
self.tree_model.invisibleRootItem().appendRow(self.out_insertions)
按预期工作(在“类别”列下插入“插入”行)。但是,如果我删除 self.out_insertion 分配,例如:
self.tree_model = QStandardItemModel()
self.tree_model.setHorizontalHeaderLabels(['Category'])
self.tree_model.invisibleRootItem().appendRow(QStandardItem("Insertions"))
它不起作用(显示一个空行)。
我正在使用 Qt 4.6.3 和 PySide 0.4.1。有人能解释一下为什么会这样吗?
提前致谢
~阿基