QListView scrolls to top when rows inserted
Hi there
I've a QListViewwith a model derived from QAbstractListModel.
In the model I want to insert some rows:
Code:
bool MembersListModel
::insertRows(int row,
int count,
const QModelIndex & parent
/*= QModelIndex()*/) { beginInsertRows(parent, row, row + count);
Q_ASSERT(m_lstTempAditionalProdData->count() == count);
for(int i=0; i<count; i++) {
Q_ASSERT(i < m_lstTempAditionalProdData->count());
m_lstProdDataForModel->insert(row+i, m_lstTempAditionalProdData->at(i));
}
endInsertRows();
return true;
}
If I insert the rows the view always scrolls to the begining of the list. I can't figure out what's hapening...
Any hints?
Thanks Luke
Re: QListView scrolls to top when rows inserted
Yes.
You can use QAbstractItemView::scrollToTop(), scollToBottom() or scrollTo() (scroll to your item with the modelIndex).
See http://doc.trolltech.com/4.6/qabstra....html#scrollTo
Your welcome.
Re: QListView scrolls to top when rows inserted
Thanks
But shouldn't the view not scroll at all when I insert items.
In an other list I've in my app the view stays at the same place when inserting rows. But I can't find the difference in the code concerning the scrolling.
But I'll try to fix with the scrollTo(...) method.
Cheers Luke