May 2019
Intermediate to advanced
542 pages
13h 37m
English
Now that our model is ready to use, let's flesh out the rest of the application to demonstrate how to use it.
To begin with, we need to create a QTableView widget and add it to our MainWindow :
# in MainWindow.__init__() self.tableview = qtw.QTableView() self.tableview.setSortingEnabled(True) self.setCentralWidget(self.tableview)
As you can see, we don't have to do much to make the QTableView widget work with the model. Because we implemented sort() in the model, we'll enable sorting, but otherwise, it doesn't require much configuration.
Of course, to see any data, we need to assign a model to the view; and in order to create a model, we need a file. Let's create a callback to get one:
def select_file(self): filename, ...
Read now
Unlock full access