iterating selected rows in a qtableview
I want to act on the selected rows in a qtableview.
I'm trying the code below, however, list.count() gives the amount of selected cells in stead of selected rows, I only need the rowcount. How do I get that please, I searched but seems I'm too dumb to find it.
Code:
const QModelIndexList list = table->selectionModel()->selection().indexes();
for (int i = 0; i < list.count(); i++)
{
int row = index.row();
QString name
= model
->record
(row
).
value("name").
toString();
qDebug() << i << row << name;
}
}
Re: iterating selected rows in a qtableview
If you used "select rows" selection behavior you could simply use QItemSelectionModel::selectedRows(). If not, you could use for example a set:
Code:
QSet<int> rows;
const QModelIndexList list = table->selectionModel()->selection().indexes();
for (int i = 0; i < list.count(); i++)
{
rows.insert(index.row());
}
qDebug() << rows;
Re: iterating selected rows in a qtableview
Quote:
Originally Posted by
jpn
If you used "select rows" selection behavior you could simply use QItemSelectionModel::selectedRows(). If not, you could use for example a set:
I have that behaviour yes, gee why didn't I see that. :)
Quote:
Originally Posted by
jpn
Code:
QSet<int> rows;
const QModelIndexList list = table->selectionModel()->selection().indexes();
for (int i = 0; i < list.count(); i++)
{
rows.insert(index.row());
}
qDebug() << rows;
Thanks for both.