How to sort data in QTableWidget?

后端 未结 5 1699
星月不相逢
星月不相逢 2020-12-06 10:31

I have a QTableWidget and the first column contains numbers from 1 to 1000. Now I need to sort the table based on this first column.

I\'m using the func

5条回答
  •  星月不相逢
    2020-12-06 11:04

    One way that worked in my situation was

    1) before filling the table, turn off sorting:

    table.setSortingEnabled(False)
    

    2) pad the number strings with blanks and make all strings in the column have the same length:

    ('    '+numStr)[-4:]
    

    3) after filling the table, turn on sorting:

    table.setSortingEnabled(True)
    

    This fixed the row sorting problem and the numerical order.

提交回复
热议问题