Results 1 to 3 of 3

Thread: sorting qsqltable on multiple columns

  1. #1
    Join Date
    Mar 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default sorting qsqltable on multiple columns

    Is there any way in Qt 4.8 to sort by multiple columns one and QSqlTableModel or QSqlRelationalTableModel and display them in a TableView?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: sorting qsqltable on multiple columns

    One approach is to place a customised QSortFilterProxyModel between the base model and the view.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,332
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    317
    Thanked 871 Times in 858 Posts

    Default Re: sorting qsqltable on multiple columns

    Quote Originally Posted by ChrisW67 View Post
    One approach is to place a customised QSortFilterProxyModel between the base model and the view.
    So to implement a multi-column sort within a proxy model, would you reimplement QSortFilterProxyModel::lessThan() in such a way that the primary column is the one on which the model is sorted, but then within lessThan(), you expand this to also look at the model indexes for the secondary, etc. columns?

    For example, if the model had columns for last name and first name, and you wanted to sort by first within last names, lessThan would first compare the left and right indexes (both of which point to entries in the last name column); if they were equal, then it would look at the corresponding indexes for the first name column.

    This would see to me to be the least invasive way of implementing a multi-level sort. Is there a better way?

Similar Threads

  1. Sorting columns of the QTableView
    By Qiieha in forum Qt Programming
    Replies: 8
    Last Post: 9th May 2011, 19:24
  2. multiple columns qtextdocument
    By xyfix in forum Newbie
    Replies: 0
    Last Post: 24th September 2009, 09:36
  3. QCompleter on multiple columns
    By akiross in forum Qt Programming
    Replies: 0
    Last Post: 9th November 2008, 16:15
  4. QTableWidget Sorting Multiple Selection
    By rhiacasta in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2006, 21:05
  5. QCheckListItem with multiple columns?
    By ecphora in forum Qt Programming
    Replies: 7
    Last Post: 12th April 2006, 05:01

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
  •  
Qt is a trademark of The Qt Company.