May 2019
Intermediate to advanced
542 pages
13h 37m
English
When developing a data-driven model-view application, the model is usually the best place to begin as this is where the most complex code will be found. Once we've put this backend in place, implementing the frontend is fairly trivial.
In this case, we need to design a model that can read and write CSV data. Copy the application template from Chapter 4, Building Applications with QMainWindow, and add an import at the top for the Python csv library.
Now, let's start building our model by subclassing QAbstractTableModel:
class CsvTableModel(qtc.QAbstractTableModel): """The model for a CSV table.""" def __init__(self, csv_file): super().__init__() self.filename = csv_file with open(self.filename) as fh: csvreader = csv.reader(fh) ...
Read now
Unlock full access