I have treeview based on proxymodel bas开发者_StackOverflow中文版ed on model. So I get a table, that can be filtered and sortered.
I just want to export current view of this table to CSV file. Just what I see, export to a file or print.
I suppose I have to use proxymodel for that, right? I cant find a method row or something like that.
Really I have to use methods data(), rowCount() and collumnCount()?
Thanks
There is a CSV reader/writer for python, which you can use in Frank Osterfeld's solution.
See http://docs.python.org/library/csv.html#examples for more examples!
import csv
writer = csv.writer(open("some.csv", "wb"))
writer.writerows(someiterable)
I'm not aware of any CSV parser or exporter for QAbstractItemModels, so I think you have to write your own exporting code, like this (pythonish pseudo-code):
for row in range(model.rowCount()):
for col in range(model.columnCount()):
value = model.index( row, col, QModelIndex() ).data( Qt.DisplayRole ).toString()
#write v, add separator...
#finish row...
Using only generic QAbstractItemModel API it works for all models, proxy or not.
精彩评论