If you want a list of selected indexes, try this
QModelIndexList indexes = listWidget->selectionModel()->selectedIndexes();
std::vector<int> indexList;
{
indexList.push_back(index.row());
}
QModelIndexList indexes = listWidget->selectionModel()->selectedIndexes();
std::vector<int> indexList;
foreach(QModelIndex index, indexes)
{
indexList.push_back(index.row());
}
To copy to clipboard, switch view to plain text mode
For a list of boolean, try this
if(model == 0)
{
QMessageBox::critical(this,
"Error",
"Wrong conversion");
}
std::vector<bool> indexes;
bool selected = false;
for(int row = 0; row < model->rowCount(); ++row)
{
selected = selectionModel->isSelected(model->index(row));
indexes.push_back(selected);
}
QItemSelectionModel* selectionModel = listWidget->selectionModel();
QAbstractListModel* model = qobject_cast<QAbstractListModel*>(listWidget->model());
if(model == 0)
{
QMessageBox::critical(this, "Error", "Wrong conversion");
}
std::vector<bool> indexes;
bool selected = false;
for(int row = 0; row < model->rowCount(); ++row)
{
selected = selectionModel->isSelected(model->index(row));
indexes.push_back(selected);
}
To copy to clipboard, switch view to plain text mode
Bookmarks