我试图使用 QStandardItemModel 来表示数据的层次结构,但是当我将 QStandardItems 添加到模型中时,我必须将它们分配在对象成员变量中,否则对象似乎被删除。
例如
self.tree_model = QStandardItemModel()
self.tree_model.setHorizontalHeaderLabels(['Category'])
self.out_insertions = QStandardItem("Insertions")
self.tree_model.invisibleRootItem().appendRow(self.out_insertions)
Run Code Online (Sandbox Code Playgroud)
按预期工作(“插入”行插入到“类别”列下)。但是如果我删除 self.out_insertion 赋值,例如:
self.tree_model = QStandardItemModel()
self.tree_model.setHorizontalHeaderLabels(['Category'])
self.tree_model.invisibleRootItem().appendRow(QStandardItem("Insertions"))
Run Code Online (Sandbox Code Playgroud)
它不起作用(显示空行)。
我正在使用 Qt 4.6.3 和 PySide 0.4.1。有人可以解释一下为什么会发生这种情况吗?
提前致谢
~亚纪
| 归档时间: |
|
| 查看次数: |
904 次 |
| 最近记录: |