PDA

View Full Version : QTableWidgte, sort by CheckBox column



Asting
6th November 2014, 10:34
Hello everyone,
I have QTableWidget with enabled sorting(clikck ti header) and last column with CheckStateRole.
The problem is that sortin by column with CheckState doesnt work. Also I tried use QCheckBox widgets and delegate for cells.
If anybody have a advice how to sort it, I would appreciate.

ChrisW67
6th November 2014, 11:10
Sorting by the column with a a checkbox does work but it sorts based on the content of the cell's DisplayRole, probably nothing in your case, not the check state.

You should use QTableView and a separate model. If you want the model to sort on a different role, order or whatever, then you should reimplement its QAbstractItemModel::sort() function. If you use a QStandardItemModel then you can use QStandardItemModel::setSortRole() instead.