Results 1 to 3 of 3

Thread: QListView scrolls to top when rows inserted

  1. #1
    Join Date
    Mar 2010
    Posts
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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:
    Qt Code:
    1. bool MembersListModel::insertRows(int row, int count, const QModelIndex & parent /*= QModelIndex()*/) {
    2. beginInsertRows(parent, row, row + count);
    3.  
    4. Q_ASSERT(m_lstTempAditionalProdData->count() == count);
    5. for(int i=0; i<count; i++) {
    6. Q_ASSERT(i < m_lstTempAditionalProdData->count());
    7. m_lstProdDataForModel->insert(row+i, m_lstTempAditionalProdData->at(i));
    8. }
    9.  
    10. endInsertRows();
    11.  
    12. return true;
    13. }
    To copy to clipboard, switch view to plain text mode 

    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
    Using Qt 4.7
    Developping on Win 7 and XP
    Using Qt Creator, Eclipse and Visual Studio
    Target Platforms Win, Linux and soon OS X

  2. #2
    Join Date
    Oct 2010
    Location
    Grenoble, France
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  3. #3
    Join Date
    Mar 2010
    Posts
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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
    Using Qt 4.7
    Developping on Win 7 and XP
    Using Qt Creator, Eclipse and Visual Studio
    Target Platforms Win, Linux and soon OS X

Similar Threads

  1. Q Scroll Area that scrolls??
    By hakermania in forum Newbie
    Replies: 6
    Last Post: 24th August 2010, 19:48
  2. QListView removing rows problems
    By vcp in forum Qt Programming
    Replies: 5
    Last Post: 15th September 2009, 19:22
  3. How to map the rows to sourceModel rows.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 11th February 2009, 08:40
  4. postgreSQL - Last Inserted ID
    By nnidza in forum Qt Programming
    Replies: 4
    Last Post: 2nd April 2007, 08:09
  5. QTreeWidget - scrolls to top when removing items
    By durbrak in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2006, 22:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.