I have some data which are represented by a class of my own ; to fix the ideas I give an example.
class MyOwnModel():
def __init__(self, name="", number=0):
self.name = name
self.number = number
I then have a list of such instances, that I want to represent in a QTableView.
li = [MyOwnModel("a", 1), MyOwnModel("b", 2)]
Then I see two strategies to make a QTableView from that :
- change
MyOwnModelso that it subclassesQAbstractTableModel - build a new
QAbstractTableModelwhich mimicsMyOwnModelin a way that its attributes are for instance twoQStringand connect thedataChangedsignal to a function which updates the instance ofMyOwnModel
I am not completely satisfied with any of these, but I have no other idea for the moment.
Which one is the most suitable to my problem ? (I have a more complex class in practice but I would like to use the same framework)
As stated in the comment, your model is your list of object. You should subclass
QAbstractTableModelto use this list.Here's my code snippet for this:
Each element of
myListis a row in the table.