0

This is the first time using Qt or pyQt, and I'm trying to make a simple list with columns. From the pyQt examples, in the basicsortfiltermode.py, which shows how to create a list with columns and which is sortable, the data collection it self is created by using a QStandardItemModel, which has insertRow and setData, but the data is made of String and QDateTime in this example.

From reading the Model-View guide as recommended by this question, I quote:

All item models are based on the QAbstractItemModel class. This class defines an interface that is used by views and delegates to access data. The data itself does not have to be stored in the model; it can be held in a data structure or repository provided by a separate class, a file, a database, or some other application component.

How would I proceed to use a python list to store data and make the view read from the list and any update on the list would be propagated in the view?

Community
  • 1
  • 1
Rui Botelho
  • 752
  • 1
  • 5
  • 18
  • If you want to stick with `QStandardItemModel`, all you need to do is `clear()` it and repopulate it with new data when list is changed. – Pavel Strakhov Jun 12 '15 at 18:51
  • How can you associate an object of interest to a ModelIndex? If I select a line, I would like to do stuff with object outside Qt! – Rui Botelho Jun 12 '15 at 23:33
  • You can use `QModelIndex::row` to get the row of the item, or use `QStandardItem::setData` and `QStandardItem::data` to attach arbitrary data to item (you can also access it with `QModelIndex::data`). – Pavel Strakhov Jun 13 '15 at 00:36

0 Answers0