Elteroooo
Elteroooo

Reputation: 3081

How to sort QTableWidget by column without clicking on the header?

I have a QTableWidget with many columns and I want to allow sorting only by specific columns. Enabling sorting for the whole table with setSortingEnabled(1) makes the table sortable by all columns,

In this example

Name        Read    Comment
whatever1    0      bla 
whatever2    0      bla
whatever3    1      bla

I want to sort the table only by column "Read" and only with the operator <.

Is there a function or slot that I can execute after each cell changes?

self.ui.table.connect.cellChanged(self.sort_by_read)

Upvotes: 1

Views: 3632

Answers (1)

Liteye
Liteye

Reputation: 2801

There exists PySide.QtGui.QTableWidget.sortItems(column[, order=Qt.AscendingOrder]) for sorting items by one specific column.

http://srinikom.github.io/pyside-docs/PySide/QtGui/QTableWidget.html#PySide.QtGui.PySide.QtGui.QTableWidget.sortItems

Upvotes: 1

Related Questions