Results 1 to 8 of 8

Thread: QAbstractTableModel and sort

  1. #1
    Join Date
    Mar 2008
    Posts
    16
    Thanks
    3
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default QAbstractTableModel and sort

    Hello, I have created my own QAbstractTableModel that uses. Now I have added the possibility to sort columns by using QSortFilterProxyModel. The problem is the model uses QList for adding new rows and when I sort a column the index between the model and QList doesnt match :S

    How can I fix it? Can some1 help me pls?

    Thank you for your help and suggestions

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

  3. #3
    Join Date
    Mar 2008
    Posts
    16
    Thanks
    3
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: QAbstractTableModel and sort

    Thank wysota for your answer

    Then I should reimplement those 2 methods. But what should they do? Sorting QList?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QAbstractTableModel and sort

    You shouldn't implement them. You should use them - they are already implemented in the proxy. The truth is you shouldn't need to use them but interface through the proxy instead of accessing the source model directly.

  5. #5
    Join Date
    Mar 2008
    Posts
    16
    Thanks
    3
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: QAbstractTableModel and sort

    Sorry if I bug you but can you make an example to be more clear please? Thank you

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QAbstractTableModel and sort

    Example of what exactly?

  7. #7
    Join Date
    Mar 2008
    Posts
    16
    Thanks
    3
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: QAbstractTableModel and sort

    How to use mapToSource

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QAbstractTableModel and sort

    Qt Code:
    1. QModelIndex proxyIndex = ...
    2. QModelIndex srcIndex = proxy->mapToSource(proxyIndex);
    To copy to clipboard, switch view to plain text mode 

    Is that what you wanted?

Similar Threads

  1. Custom sort with QTableWidget
    By nicolas44 in forum Qt Programming
    Replies: 1
    Last Post: 9th August 2007, 00:47

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.