Results 1 to 20 of 24

Thread: Possible conversion from QStandardItemModel to QAbstractTableModel?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Dec 2014
    Posts
    48
    Qt products
    Qt3 Qt4 PyQt3 PyQt4
    Platforms
    Windows
    Thanks
    23
    Thanked 1 Time in 1 Post

    Default Re: Possible conversion from QStandardItemModel to QAbstractTableModel?

    Thanks for the quickness anda_skoa
    In this manner (?) :

    Qt Code:
    1. class CSVModel(QtCore.QAbstractTableModel):
    2. def __init__(self, CSVdata, fileName, parent = None):
    3. QAbstractTableModel.__init__(self, parent)
    4. self.CSVreader.rows = CSVdata
    5. def rowCount(self, parent):
    6. return len(self.CSVreader.rows)
    7. def columnCount(self, parent):
    8. return len(self.CSVreader.header)
    9. def data(self, index, role):
    10. self.CSVreader.rows[index.row()][index.column()]
    11. def CSVreader(self,fileName):
    12. header = []
    13. rows = []
    14. with open(fileName, "rb") as fileInput:
    15. for idx, row in enumerate(csv.reader(fileInput)):
    16. headIDx = 0
    17. if idx is headIDx:
    18. header.append(row)
    19. elif idx>headIDx:
    20. items = [field for field in row]
    21. rows.append(items)
    To copy to clipboard, switch view to plain text mode 
    Last edited by jkrienert; 24th December 2014 at 19:27. Reason: code error(s)

Similar Threads

  1. Update QAbstractTableModel?
    By adutzu89 in forum Newbie
    Replies: 2
    Last Post: 4th June 2014, 22:17
  2. TableView and QAbstractTableModel
    By MattieB in forum Newbie
    Replies: 1
    Last Post: 11th December 2013, 21:57
  3. QAbstractTableModel and sort
    By foxyproxy in forum Qt Programming
    Replies: 7
    Last Post: 25th March 2008, 10:30
  4. Using QAbstractTableModel.parent
    By Max Yaffe in forum Newbie
    Replies: 7
    Last Post: 15th June 2007, 16:21
  5. QAbstractTableModel for QTreeView?
    By Michiel in forum Qt Programming
    Replies: 5
    Last Post: 15th May 2007, 10:09

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.