4

I have QStandardItemModel and the data are represented as lists

model = QtGui.QStandardItemModel(0, 2)
myrow = [1, "B"]

My first solution how to add the row was with function setData()

model.insertRow(0)
for i,item in enumerate(myrow):
    model.setData(model.index(0, i), item)

But it's extremely slow and I have performance problems already for 500 rows, it takes 1 second.

Than I've tried adding whole row at once.

model.insertRow(0, [QtGui.QStandardItem(item) for item in myrow ])

It is more faster, but it doesn't work properly.

print "setData() 2.row - ",model.data(model.index(1,0)).toInt()
print "insertRow() 1.row - ",model.data(model.index(0,0)).toInt()

And I get different outputs.

 setData() 2.row - (1, True)
 insertRow() 1.row - (0, False)

any Idea why? Is there any other way how to add whole row to the model?

Meloun
  • 13,601
  • 17
  • 64
  • 93

0 Answers0