Results 1 to 4 of 4

Thread: wrong sort in qtableview

  1. #1
    Join Date
    Jun 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default wrong sort in qtableview

    Hello,

    i am working with a QTableView under Qt4.5.1. I add headers and columns by programcode. After this i add my data in a loop from a stringfile.
    I set tableview->setSortingEnabled(true)

    Now my problem:

    the original data are:

    1. xxxx
    2. xxxx
    3. xxxx
    4. xxxx
    ....
    500. xxxx

    after sort i had:

    100: xxxx
    101: xxxx
    ...
    10: xxxx
    110: xxxx
    112: xxxx
    ...
    11: xxxx
    120: xxxx
    etc.

    How can i sort the columns right?

  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: wrong sort in qtableview

    and here we go again. Please use our search engine first before posting! Catchwords "sort number" would have lead you to the solution!

    Use QTableWidgetItem::setData() for setting an int value, then the sort will be correct.

  3. #3
    Join Date
    Jun 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: wrong sort in qtableview

    nice answer thx
    but what happend if you have first numbers and after this letters in the same column?

  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: wrong sort in qtableview

    Quote Originally Posted by toem View Post
    nice answer thx
    but what happend if you have first numbers and after this letters in the same column?
    split the string in two parts number and text, add two hidden colums to your table and sort after them. Or you have to write your own sort algorithm, if it is too much to duplicate your data...

Similar Threads

  1. Replies: 2
    Last Post: 7th June 2009, 10:47
  2. qtableview sort question?
    By yunpeng880 in forum Qt Programming
    Replies: 2
    Last Post: 3rd March 2009, 09:28
  3. Replies: 3
    Last Post: 29th January 2009, 08:38
  4. QTableView
    By dragon in forum Qt Programming
    Replies: 0
    Last Post: 22nd September 2008, 16:53
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49

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.