[PySide] custom table sorting
sebastian at risefx.com
Fri Apr 6 12:03:21 CEST 2012
assuming the checkboxes and the combo boxes are different data types
(bool, vs, string) and thus displayed in different columns, sorting
should happen automatically when you setSortingEnabled(True). Please
note that you have to disable sorting while inserting items because this
may lead to stringe behaviour. Also if you want to display checkboxes
these should be set by
Qt.ItemIsUSerCheckable)) and setCheckState() rather than doing a
QTableWidget.setCellWidget(), because this is way faster. The combooxes
can be inserted with setCellWidget, but be aware that you may run into
performance issues if you add a lot of them.
Alternatively you could subclass the QTableWidgetItem and override the <
operator to provide your own sorting, which will be - of course -
solower because implemented in python.
Finally when dealing with large datasets I would recommend going for the
true model/view approach with QTableView, QTableModel and
QStyledItemDelegate, but those are more hard to use.
Am 06.04.2012 02:50, schrieb Frank Rueter | OHUfx:
> Hi guys,
> I'm working on a table that has ItemWidgets (comboBoxes, checkBoxes etc)
> in some cells and I'm trying to figure out how to write a custom sort
> behaviour that will enable me to sort the table by columns containing
> widgets using the respective widgets' current value (e.g. show all rows
> with a checked checkBox first, followed by all rows with an unchecked
> Has anyone done this before?
> Any pointers would be fabulous!
> PySide mailing list
> PySide at qt-project.org
More information about the PySide