Sorting data in QTableWidget
-
Hello,
I would like to ask you a question.
My goal is to sorting files in ascending order. I have chosen "SortingEnabled" true from mainwindow.ui. But "Lines" column is not sorted by ascending order.
My output is here:
Thanks in advance!@eefesafak said in Sorting data in QTableWidget:
But "Lines" column is not sorted by ascending order.
?? What row is not sorted by the value in Lines column, ascending, that you show? And as it happens this is ascending by either number or string, so either way it's sorted ascending....
-
@eefesafak said in Sorting data in QTableWidget:
But "Lines" column is not sorted by ascending order.
?? What row is not sorted by the value in Lines column, ascending, that you show? And as it happens this is ascending by either number or string, so either way it's sorted ascending....
@JonB said in Sorting data in QTableWidget:
What row is not sorted by the value in Lines column, ascending, that you show? And as it happens this is ascending by either number or string, so either way it's sorted ascending...
For example, On line 798 and 799, 11 is not greater than 110.
-
@JonB said in Sorting data in QTableWidget:
What row is not sorted by the value in Lines column, ascending, that you show? And as it happens this is ascending by either number or string, so either way it's sorted ascending...
For example, On line 798 and 799, 11 is not greater than 110.
@eefesafak
Exactly, and since you asked for ascending11
comes before110
which comes before111
....Do you understand that "ascending" means the lowest values at the start (lowest index, visual top of the list) and highest values at the end (highest index, visual bottom of the list, and continuing to get higher if you scroll down to reveal more rows)?
Try clicking the Lines header a second time, see what that looks like? That should be descending....
-
@eefesafak
Exactly, and since you asked for ascending11
comes before110
which comes before111
....Do you understand that "ascending" means the lowest values at the start (lowest index, visual top of the list) and highest values at the end (highest index, visual bottom of the list, and continuing to get higher if you scroll down to reveal more rows)?
Try clicking the Lines header a second time, see what that looks like? That should be descending....
-
@eefesafak said in Sorting data in QTableWidget:
Datas in "Lines" column are QString, not int.
But you are missing/confusing the point. I wrote earlier:
And as it happens this is ascending by either number or string, so either way it's sorted ascending....
From what you show, it is sorted ascending in either/both of string or number.
110 > 11
holds whether you treat them as numbers or strings.Now, this will not always be the case for some numbers/strings. E.g. as number
20 > 3
, but as a string20 < 3
. So it will depend which items in your list.QTableWidget
will do the sort/comparison however you entered items into it. If you did so a strings it will sort by string, if your did so as numbers/int
s it will sort by numeric value. You probably want the latter, so make sure you add thelines
column values as numbers, not strings, into theQTableWidget
.... -
@eefesafak said in Sorting data in QTableWidget:
Datas in "Lines" column are QString, not int.
Because you added them as QString, not int.