不啰嗦,直接上代码:
std::vector<int> vecItemIndex;//保存选中行的索引
QItemSelectionModel *selections = ui.fileTable->selectionModel(); //返回当前的选择模式
QModelIndexList selectedsList = selections->selectedIndexes(); //返回所有选定的模型项目索引列表
for (int i = 0; i < selectedsList.count(); i++)
{
vecItemIndex.push_back(selectedsList.at(i).row());
}
std::sort(vecItemIndex.begin(), vecItemIndex.end());
vecItemIndex.erase(std::unique(vecItemIndex.begin(), vecItemIndex.end()), vecItemIndex.end());