[PyQt] Maintaining index after sort
Marc Rossi
mrossi19 at gmail.com
Sun May 29 21:06:17 BST 2011
Thanks for the reply. There must be some core concept of Qt/Model-View
programming I am just missing.
Makes sense that I can store the data keyed by symbol in the model and
update it that way, but I thought I had to emit a dataChanged signal for the
view to update as shown below:
self.emit(SIGNAL("dataChanged(QModelIndex,QModelIndex)"),
self.index(index.row(), COL1), self.index(index.row(), COL5))
Doing it this way required me to have the index for the column I wanted
refreshed. I see there is a 'match()' function in the QAbstractItemModel
class but when I tried that (calling match for every update) things were
ridiculously slow.
Marc
On Sun, May 29, 2011 at 4:03 AM, Andreas Pakulat <apaku at gmx.de> wrote:
> On 28.05.11 21:58:36, Marc Rossi wrote:
> > 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.
>
> Model indexes are not meant to be stored over time, they're short-lived
> objects. You could try Persistent Model Indexes, which are meant to be
> stored.
>
> But you don't need the index at all, your model just needs a function
> that takes the sinfo and updates its internal structure by using
> sinfo.symbol to identify which entry to update. In fact I think the
> if/else you've showed should be part of the model, so that the outside
> can simply do something like: model.addData(sinfo).
>
> Andreas
>
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110529/3e4605ce/attachment.html>
More information about the PyQt
mailing list