Results 1 to 4 of 4

Thread: QTableWidget - setSortingEnabled

  1. #1
    Join Date
    Jan 2007
    Posts
    91
    Thanks
    21
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Question QTableWidget - setSortingEnabled

    Hello,
    I have enabled sorting using the setSortingEnabled call on a QTablewidget.

    How do I control how it sorts. For example, I have a column with number that I want sorted numerically, not alphabetically, how do I do that? I also want to sort case-insensitive, rather than case sensitive, how do I do that?

    - BRC

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

    Default Re: QTableWidget - setSortingEnabled

    For numerical sortiing, set the data as integers, not as text:
    Qt Code:
    1. QTableWidgetItem* item = ...
    2. // item->setText("2"); // <-- not like this
    3. item->setData(Qt::DisplayRole, 2); // but this
    To copy to clipboard, switch view to plain text mode 

    For case insensitive sorting, you might need to reimplement QTableWidgetItem::operator<().
    J-P Nurmi

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

    bruccutler (25th April 2007)

  4. #3
    Join Date
    Jan 2007
    Posts
    91
    Thanks
    21
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QTableWidget - setSortingEnabled

    Thanks for the reply.

    "Roles" are a bit confusing. Where's a good reference on what Qt means by "roles"?

    Again, thanks for the help.
    - BRC

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

    Default Re: QTableWidget - setSortingEnabled

    Quote Originally Posted by bruccutler View Post
    "Roles" are a bit confusing. Where's a good reference on what Qt means by "roles"?
    J-P Nurmi

Similar Threads

  1. QTableWidget (resizing rows, turning off selection, etc.)
    By kiss-o-matic in forum Qt Programming
    Replies: 6
    Last Post: 11th January 2007, 01:57
  2. QTableWidget issues
    By Djony in forum Qt Programming
    Replies: 42
    Last Post: 19th December 2006, 23:27
  3. print QTableWidget
    By chak_med in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 18:46
  4. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46
  5. Replies: 6
    Last Post: 5th March 2006, 21:05

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.