Through view's selection model:
QItemSelectionModel * QAbstractItemView::selectionModel () const
Returns the current selection.
Through view's selection model:
QItemSelectionModel * QAbstractItemView::selectionModel () const
Returns the current selection.
Hi JPN!
Should this return me a integer value?Have you see somewhere a example?I have pain for construct it![]()
Think DigitalGasoline
Did you even try?Originally Posted by raphaelf
Anyway, for a row index as an integer you can use something like this:
Qt Code:
// Get all selections QModelIndexList indexes = view->selectionModel()->selection().indexes(); for (int i = 0; i < indexes.count(); ++i) { // To get the row/column numbers use index.row() / index.column() }To copy to clipboard, switch view to plain text mode
hI jpn!
I cant see where should i use index.row(); ?
It's a great pity that QTableView has not a function for that![]()
for count selected rows work:
Qt Code:
QModelIndexList indexes = ui.tableView->selectionModel()->selection().indexes(); for (int i = 0; i < indexes.count(); ++i) { }To copy to clipboard, switch view to plain text mode
Think DigitalGasoline
The selection list contains an index model per every selected item (cell in a table model).
If you had selected a single row, for example, the list would contain an item per each cell on that row.
Depending on the selection mode and behaviour of your view, the selection list contents may vary a lot, of course.
So you wanted to get the "selected row". Then I suppose the selection behaviour is SelectRows and selection mode is SingleSelection..
If so, due to the fact that all indexes in the selection list would represent different cells in a same row, you could just ask index.row() from the first index in the list and ignore others..
postb99 (20th February 2014)
Hello,
if you don't want to mess around with Qts interview classes you might also intercept the tree's selection changed signal to your slot..
Hi raphaelf
Maybe this will help u
Qt Code:
QModelIndexList selectedList = ui->tabel->selectionModel()->selectedRows(); for( int i=0; i<selectedList.count(); i++)To copy to clipboard, switch view to plain text mode
postb99 (20th February 2014), RoyBellingan (12th July 2013), sattu (5th October 2011)
The last suggestion is true if the selection mode is "selectrows"
Qtableview is default to selectitems.
Bookmarks