[PyQt] Maintaining index after sort

Marc Rossi mrossi19 at gmail.com
Sun May 29 03:58:36 BST 2011


Hi all.  Hopefully this is the correct place.  Google searches etc, came up
empty although I have to think this is a common question.

I have a Model-View app using the QAbstractTableModel as the base class for
my model.  As I receive data across the tcp pipe (using PyZMQ) I check if
this is a new item or an update by looking to see if I already have an index
for the data received.

                if (sinfo.symbol not in symbols):
                    row = form.model.rowCount()
                    form.model.insertRow(row, sinfo.symbol)
                    index = form.model.index(row, 0)
                    symbols[sinfo.symbol] = index
                    form.model.setRiskData(index, sinfo)
                else:
                    index = symbols[sinfo.symbol]
                    form.model.setRiskData(index, sinfo)

All works well until I sort, then all my previously stored indices have the
wrong rows.  How do you handle this?   Obviously if I disable sorting all
works fine, but that is not an option.  This seems like there is probably an
obvious solution that for some reason I can't find.  Help would be much
appreciated.

Thanks
Marc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110528/9daab00c/attachment.html>


More information about the PyQt mailing list