Results 1 to 4 of 4

Thread: QTableWidget and sorting like int

  1. #1
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default QTableWidget and sorting like int

    Hi

    I've a QTableWidget TabelaLista, and I set a sorting Enable by:
    Qt Code:
    1. TableLista->setSortingEnabled(false);
    To copy to clipboard, switch view to plain text mode 

    Now, in one of columns i've a strings like:

    1/01/2000
    2/01/2000
    3/02/3000
    11/03/2000
    etc...
    now, I would like to sort only by first part like int (ftom char 0 to char /). Now QT sorting like a string:

    1/01
    11/01
    2/01
    3/02
    I'ld like somthing like:
    1/01
    2/01
    3/02
    11/01
    how do this? Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTableWidget and sorting like int

    create a hidden column where you store only the first (integer) part of the string. And then sort for that column. Or create your own QSortFilterProxyModel and define a proper sort function. (QSortFilterProxyModel::lessThan())

  3. #3
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget and sorting like int

    Thanks, but how connect "signal" on push by sorting on column (example 2) and sort by column 3 (hidden)?

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTableWidget and sorting like int

    good point. If the user should be able to sort via the header than it's difficult to catch/suppress the right signal from QHeaderView. Another possibility is to simple subclass a QTableWidgetItem and change only QTableWidgetItem::operator<(). Use you own item for that column. That's not so nice as with a proxy sort model but easier.

Similar Threads

  1. QTableWidget sorting
    By abrou in forum Newbie
    Replies: 2
    Last Post: 6th June 2012, 10:53
  2. Sorting a qtablewidget......
    By reshma in forum Qt Programming
    Replies: 8
    Last Post: 23rd March 2009, 14:34
  3. QTableWidget sorting
    By losiem in forum Qt Programming
    Replies: 4
    Last Post: 14th July 2008, 20:20
  4. QTableWidget Sorting Widgets!
    By VireX in forum Qt Programming
    Replies: 4
    Last Post: 14th April 2007, 01:08
  5. QTableWidget Sorting
    By mclark in forum Newbie
    Replies: 4
    Last Post: 29th September 2006, 22:34

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.