PDA

View Full Version : QListView scrolls to top when rows inserted



woodtluk
8th October 2010, 15:19
Hi there

I've a QListView with a model derived from QAbstractListModel.

In the model I want to insert some rows:

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

Davton
8th October 2010, 16:08
Yes.
You can use QAbstractItemView::scrollToTop(), scollToBottom() or scrollTo() (scroll to your item with the modelIndex).

See http://doc.trolltech.com/4.6/qabstractitemview.html#scrollTo

Your welcome.

woodtluk
8th October 2010, 16:26
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