// 获取指定的列索引集合
QList<int> QcViewBaseForm::getSelectedColumns(QTableWidget* tableWidget) {
QList<int> selectedColumns;
QList<QTableWidgetSelectionRange> selectedRanges = tableWidget->selectedRanges();
for (auto range : selectedRanges) {
for (int col = range.leftColumn(); col <= range.rightColumn(); ++col) {
if (!selectedColumns.contains(col)) {
selectedColumns.append(col);
}
}
}
return selectedColumns;
}
// 获取指定的行索引集合
QList<int> QcViewBaseForm::getSelectedRows(QTableWidget* tableWidget) {
QList<int> selected_rows;
QList<QTableWidgetItem*> selected_items = tableWidget->selectedItems();
for (int i = 0; i < selected_items.size(); ++i) {
int row = selected_items[i]->row();
if (!selected_rows.contains(row)) {
selected_rows.append(row);
}
}
std::sort(selected_rows.begin(), selected_rows.end());
return selected_rows;
}
标签:rows,获取,QTableWidget,索引,tableWidget,selected,QList,row
From: https://www.cnblogs.com/faithlocus/p/17309735.html