Results 1 to 5 of 5

Thread: Refresh QTableView after sorting

  1. #1
    Join Date
    Dec 2008
    Posts
    32
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Refresh QTableView after sorting

    I have model-view application - a table with many rows in it.
    There is sorting enabled at the header of this table. (To sort data in the table I use Proxy model because without it sorting didn't work). The app works well except one little thing:
    1. I select row in the table
    2. I click on a column in the header to sort data
    3. There is no auto-scroll to the raw I selected before sorting.

    i.e. if my table has 100 rows and on the screen I can see only 20 of them, and I choose 1st raw, then press "sort", chosed row goes to the bottom of table and it would be nice if the application automatically scroll QTableView to show my row. How can I do this? Thank you!
    Last edited by araglin; 18th December 2008 at 20:09.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Refresh QTableView after sorting

    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    araglin (18th December 2008)

  4. #3
    Join Date
    Dec 2008
    Posts
    32
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Refresh QTableView after sorting

    Thanks!
    Think that something like this must work out:
    Qt Code:
    1. connect( header, SIGNAL(clicked( const QModelIndex&) ), tableView, SLOT(scrollTo( const QModelIndex& ) ) );
    To copy to clipboard, switch view to plain text mode 

    But I think it's necessary to replace QModelIndex& of SIGNAL(clicked) to the index of the element in the row I chosed before. That's the problem for me. Would you please tell me right way to do this operation?

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Refresh QTableView after sorting

    Unfortunately scrollTo() is not a slot so you have to implement a custom slot that further calls that function. Also, QHeaderView::sortIndicatorChanged() might be more reliable than the clicked() signal.
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    araglin (18th December 2008)

  7. #5
    Join Date
    Dec 2008
    Posts
    32
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Refresh QTableView after sorting

    Ok, thanks for advices! I'll try to implement something

Similar Threads

  1. QTableView sorting
    By gabriels in forum Qt Programming
    Replies: 11
    Last Post: 6th October 2010, 17:13
  2. QTableView refresh
    By eleanor in forum Qt Programming
    Replies: 9
    Last Post: 6th October 2007, 18:00
  3. QTableView refresh problem
    By tebessum in forum Qt Programming
    Replies: 3
    Last Post: 29th December 2006, 11:22
  4. Replies: 9
    Last Post: 7th November 2006, 15:10
  5. Sorting QTableView
    By Jimmy2775 in forum Qt Programming
    Replies: 7
    Last Post: 9th February 2006, 16:47

Tags for this Thread

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.