Results 1 to 3 of 3

Thread: any solution to QtableView sorting?

  1. #1
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default any solution to QtableView sorting?

    i ve read in this forum the next statement
    Hi

    Using Qt 4.1.3 (release, linux)

    The actual problem is in QTableView.
    It is not possible to enable sorting in QTableView as the actual connect to sortByColumn is made in QTableWidget and not in QtableView.
    If you compare this with QTreeView, you'll notice that these connects are moved to QTreeView.
    This should be done by Trolltech guys as well for QTableView.
    Just compare code difference in qt source where they connect sortByColumn and you'll understand.

    BTW: When using sort function in your widget you'll notice that the sort works fine in QTableView. Only the connections when clicking the header are made at the wrong place (In QTableWidget instead of in QTableView).

    I hope this explains the original problem in this topic.
    And I hope they come with a fix. By the way I did not check snapshot code to see if it is already fixed.

    in fact im working with a QTableView that is connected to a QsqlQueryModel, the problem is that when i do

    Qt Code:
    1. tableView.setSortingEnabled (true)
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. tableView.sortByColum (0, Qt::AscendingOrder)
    To copy to clipboard, switch view to plain text mode 

    for example, it has no effect...

    any solution with QtableView? shoul i change this to a QtableWidget?

    thanks everyone

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

    Default Re: any solution to QtableView sorting?

    I would expect it to work as-is, but I haven't tried exactly the combination you are complaining about.

    If you just want the data sorted in one way, and not user controlled, then just put an "ORDER BY" clause into your SQL.

    If you want user control of sorting then try putting a QSortFilterProxyModel between the base model and your view.

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

    KillGabio (25th January 2012)

  4. #3
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: any solution to QtableView sorting?

    SOLVED!! using QsortFilterProxyModel thankkkks!

Similar Threads

  1. QTableView sorting
    By realdarkman71 in forum Newbie
    Replies: 12
    Last Post: 1st December 2010, 22:45
  2. QTableView sorting
    By gabriels in forum Qt Programming
    Replies: 11
    Last Post: 6th October 2010, 17:13
  3. QTableView sorting problem
    By noktus in forum Newbie
    Replies: 11
    Last Post: 23rd April 2008, 10:20
  4. QTableView sorting
    By Bojan in forum Newbie
    Replies: 2
    Last Post: 28th September 2006, 08:11
  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.