//递归遍历
点击查看代码
void iterateTreeViewNodes(const QModelIndex& parentIndex, QStandardItemModel* model, QVector<QStandardItem*>& items)
{
int rowCount = model->rowCount(parentIndex);
int columnCount = model->columnCount(parentIndex);
for (int row = 0; row < rowCount; ++row) {
for (int column = 0; column < columnCount; ++column) {
QModelIndex index = model->index(row, column, parentIndex);
QStandardItem* item = model->itemFromIndex(index);
items.push_back(item);
iterateTreeViewNodes(index, model, items);
}
}
}