Results 1 to 3 of 3

Thread: Sort QTableWidgetItem column with doubles

  1. #1
    Join Date
    Aug 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Sort QTableWidgetItem column with doubles

    Hi,
    I'm sure that there is a simple solution to this, but nothing I've tried seems to work... I have a column in my table with entries that are decimal numbers. When I try to sort according to the column, it essentially ignores the decimal point. Thus sorted results come in orders such as:

    19.2
    19.6
    2
    2.4
    etc...

    I've tried using setData and passing the values without converting to text and that didn't resolve the issue. Also, I'm using Qt version 4.2, perhaps this has been changed in a more recent version. Thank you for any help you can provide!

    -Michael

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

    Default Re: Sort QTableWidgetItem column with doubles

    For QTableWidgetItems, setting the data as numerical values (instead of as text with setText()) has worked as long as I can remember:
    Qt Code:
    1. item->setData(Qt::DisplayRole, 19.2);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Aug 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Sort QTableWidgetItem column with doubles

    jpn,
    Thanks for the reply. Interestingly, I tried just rounding my numbers and setData with integers, in which case it works fine (although it won't sort properly if the values are set with setText, even for integers). The incorrect sorting with doubles must just be an issue with my particular version or something - I'll let you know if I made a more fundamental mistake.

    -Michael

Similar Threads

  1. Focus of cells in a QTableWidget
    By SailinShoes in forum Qt Programming
    Replies: 4
    Last Post: 9th June 2008, 08:19
  2. QTreeWidget Single Column Sort Disable
    By craigjameshamilton in forum Newbie
    Replies: 1
    Last Post: 21st April 2008, 08:08
  3. How to set a column readonly in qtablewidgetitem
    By ashukla in forum Qt Programming
    Replies: 6
    Last Post: 8th November 2007, 13:23

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.