[PySide] custom table sorting
Frank Rueter | OHUfx
frank at ohufx.com
Sun Apr 8 00:23:58 CEST 2012
will do, thanks
On 7/04/12 9:27 PM, Sebastian Elsner wrote:
> I recommend reading the appropriate chapters in this book:
> http://www.qtrac.eu/pyqtbook.html
> and have a look this ressource: http://www.yasinuludag.com/blog/
> also download a version of PyQt, it has all original Qt examples
> (including the model view thingies) translated to python, which helps a
> lot and is a good starting point.
>
> Am 07.04.2012 02:00, schrieb Frank Rueter | OHUfx:
>> 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
>>>> PySide at qt-project.org
>>>> http://lists.qt-project.org/mailman/listinfo/pyside
>>> _______________________________________________
>>> PySide mailing list
>>> PySide at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/pyside
>> _______________________________________________
>> PySide mailing list
>> PySide at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/pyside
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
More information about the PySide
mailing list