1、获取批量选中项
std::vector<int> Item_sum;//选中行
QItemSelectionModel *selections = ui->listWidget->selectionModel(); //返回当前的选择模式(这个地方我是自绘控件,使用this->selectionModel())
QModelIndexList selectedsList = selections->selectedIndexes(); //返回所有选定的模型项目索引列表
for (int i = 0; i < selectedsList.count(); i++)
{
Item_sum.push_back(selectedsList.at(i).row());
}
std::sort(Item_sum.begin(), Item_sum.end());
Item_sum.erase(std::unique(Item_sum.begin(), Item_sum.end()), Item_sum.end());
Item_sum.size();个数
2、使用键盘设置全选:https://blog.youkuaiyun.com/bigtree_mfc/article/details/105723742
3、设置按住Ctrl+鼠标点击多选:
this->setSelectionMode(QAbstractItemView::ExtendedSelection);
4、获取拖拽到的列表当前序号位置
row(itemAt(event->pos()));//QDropEvent *event
未完待续