Chris Ray
Chris Ray

Reputation: 81

How to sort a QTableWidget by column by clicking on the header of the column?

I am building a database for my work. I want to be able to sort the elements in a manner similar to how you can sort elements in excel by clicking the header of a column. I am using the pandas library so I plan on sorting with that, but my main question is is there a way to run code when a header is clicked in a QTableWidget? Or is this not possible?

Upvotes: 5

Views: 6884

Answers (1)

AlexLaur
AlexLaur

Reputation: 385

You can do that by using the property of the QtableView :

table = QtWidgets.QTableWidget()
table.setSortingEnabled(True)

Upvotes: 14

Related Questions