May 2019
Intermediate to advanced
542 pages
13h 37m
English
While we can edit the list, we can't yet add or remove items in the list; let's add that capability before we move on to the coffee form itself.
Start by creating some toolbar actions pointing to MainView methods:
toolbar = self.addToolBar('Controls') toolbar.addAction('Delete Coffee(s)', self.delete_coffee) toolbar.addAction('Add Coffee', self.add_coffee)
Now we'll write the MainView methods for those actions:
def delete_coffee(self): selected = self.coffee_list.selectedIndexes() for index in selected or []: self.coffees_model.removeRow(index.row()) def add_coffee(self): self.stack.setCurrentWidget(self.coffee_list) self.coffees_model.insertRows( self.coffees_model.rowCount(), 1)
To delete a row from the model, ...
Read now
Unlock full access