Hi Sebastian, thanks again for your help. I couldn't get the sorting to work even though the widgets in each column were always the same type. You are probably totally right that this won't be very scalable, I just wanted to get a grip on it first before diving into the QTableView/QTableModel solution, which I think I won't be able to avoid. These tables can indeed grow very large. I shall read up on this though and try and do it properly. ;)
Cheers, frank On 6/04/12 10:03 PM, Sebastian Elsner wrote: > Hi, > > 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 > QTableWidgetItem.setFlags(QTablewidgetItem.flags() | > 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. > > Cheers > > Sebastian > > > 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 >> checkBox). >> >> Has anyone done this before? >> Any pointers would be fabulous! >> >> Cheers, >> frank >> >> _______________________________________________ >> PySide mailing list >> [email protected] >> http://lists.qt-project.org/mailman/listinfo/pyside > _______________________________________________ > PySide mailing list > [email protected] > http://lists.qt-project.org/mailman/listinfo/pyside _______________________________________________ PySide mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/pyside
