migel
4th October 2011, 17:13
Sorting visually works great using QTableView sort headers or custome soring implementation in QSortFilterProxyModel.
But when I emit pressed(const QModelIndex &) signal it gives an index before the sort. so let say I have 3 rows,
1
2
3
pressed(const QModelIndex &) on 1 GIVES 1
then sort the using table header.
3
2
1
pressed(const QModelIndex &) on 3 GIVES 1
To get correct item from index I have used several methods, I was using also proxy model to get the item. I's all wrong, it just the pressed(const QModelIndex & INDEX ) INDEX is not right always gives me the index on row before SORTING.
Currently I use this
QStandardItem *item = model()->item(index.row(),0);
tried to get an index form proxy base on the clicked row.
QModelIndex index = _proxyModel->index(indexs.row(),0,QModelIndex());
ONE MORE
The index.row() is correct clicked on seconds row goves 2, it jast the data in there.
Thoughts ?
Added after 25 minutes:
And here is a fix!
http://stackoverflow.com/questions/3586718/cant-use-itemfromindex-in-clicked-signal-of-qtreeview-with-qsortfilterproxymodel
But when I emit pressed(const QModelIndex &) signal it gives an index before the sort. so let say I have 3 rows,
1
2
3
pressed(const QModelIndex &) on 1 GIVES 1
then sort the using table header.
3
2
1
pressed(const QModelIndex &) on 3 GIVES 1
To get correct item from index I have used several methods, I was using also proxy model to get the item. I's all wrong, it just the pressed(const QModelIndex & INDEX ) INDEX is not right always gives me the index on row before SORTING.
Currently I use this
QStandardItem *item = model()->item(index.row(),0);
tried to get an index form proxy base on the clicked row.
QModelIndex index = _proxyModel->index(indexs.row(),0,QModelIndex());
ONE MORE
The index.row() is correct clicked on seconds row goves 2, it jast the data in there.
Thoughts ?
Added after 25 minutes:
And here is a fix!
http://stackoverflow.com/questions/3586718/cant-use-itemfromindex-in-clicked-signal-of-qtreeview-with-qsortfilterproxymodel