void traverseTreeView(const QModelIndex &index, const QAbstractItemModel *model, QStringList &stringList) {
if (!index.isValid()) {
return;
}
// 获取当前项的文本并添加到 QStringList 中
QString text = model->data(index, Qt::DisplayRole).toString();
if (!text.isEmpty()) {
stringList.append(text);
}
// 递归遍历子项
for (int row = 0; row < model->rowCount(index); ++row) {
for (int col = 0; col < model->columnCount(index); ++col) {
traverseTreeView(model->index(row, col, index), model, stringList);
}
}
}
QStringList getAllItemsText(QTreeView *treeView) {
QStringList stringList;
QAbstractItemModel *model = treeView->model();
if (model) {
// 从根节点开始遍历
traverseTreeView(treeView->rootIndex(), model, stringList);
}
return stringList;
}
11-25
925

12-15
525

12-16
954

09-09
1826

07-22
6328
