PDA

View Full Version : Table Sorting



ToddAtWSU
25th January 2007, 14:37
I have a QTable in Qt 3.3.7 and have it working so I can sort the columns. The one problem is some of my columns contain numerical values and the QTable only sorts by strings. So if I have the numbers 1-30 in a row in my table and I sort that row from lowest to highest, 10-19 is lower than 2 and anything else because "1" comes before "2" in a string. So how do I need to go about doing this? Is there a nice convenience in Qt 3 that I am just not seeing? Thanks for your help!

e8johan
25th January 2007, 14:55
Look at example 13-6 here: http://www.digitalfanatics.org/projects/qt_tutorial/chapter13.html .

ToddAtWSU
29th January 2007, 20:33
I have looked at the example but I don't know how this helps me. I am storing data into a QTable and I don't have the ability to overwrite a compare function like the QListViewItem has. I am storing QVariant data into the QTable. I feel like I need a QTable over a QListView because I need to be able to hide and show rows and do not see how to do this with a QListView. Or is there an easy way to show/hide rows (not columns) inside a QListView? Does anybody else have any other ideas?

ToddAtWSU
30th January 2007, 14:49
I have read in many places where it says to modify QTableItem::key( ) for sorting purposes but how do I set it up so I can return an integer for 3 columns in my table and a QString for the other 4 columns in my table? I don't see how it can have 2 different return types and how it will know which column calls it so it will know which return type to return. Thanks!