【发布时间】:2019-06-23 11:35:29
【问题描述】:
我有一个 QTableView 显示我的模型中特定 QModelIndex 的子级(它具有分层数据,表格当然不能显示)。我希望能够遍历表视图中的所有项目,即 rootIndex 的所有子项。我怎样才能有效地做到这一点?我使用 table.rootIndex() 引用了父索引,但是我看不到任何方法可以在不迭代整个模型的情况下迭代索引的子索引,这似乎是错误的。
这是 QSortFilterProxyModel 在表中安装模型子集的工作吗?我刚才说的有道理吗?!
这是一个启动和运行的快速示例
class Sample(QtGui.QDialog):
def __init__(self):
super(Sample, self).__init__()
model = QtGui.QStandardItemModel(self)
parent_index1 = QtGui.QStandardItemModel("Parent1")
model.appendRow(parent_index1)
parent_index2 = QtGui.QStandardItemModel("Parent2")
model.appendRow(parent_index2)
one = QtGui.QStandardItem("One")
two = QtGui.QStandardItem("Two")
three = QtGui.QStandardItem("Three")
parent_index1.appendRows([one, two, three])
table = QtGui.QTableView(self)
table.setModel(model)
table.setRootIndex(model.index(0,0))
# okay now how would I loop over all 'visible' rows in the table? (children of parent_index1)
【问题讨论】:
-
@eyllanesc 你是标签编辑大师,谢谢
标签: python pyqt pyqt4 qstandarditemmodel