May 2019
Intermediate to advanced
542 pages
13h 37m
English
The model-view pattern is not only useful in the design of large applications, but also on a smaller scale with widgets that contain data. Copy the application template from Chapter 4, Building Applications with QMainWindow, and let's look at a simple example of how model-view works on the widget level.
In the MainWindow class, create a list of items and add them to both the QListWidget and QComboBox objects:
data = [ 'Hamburger', 'Cheeseburger', 'Chicken Nuggets', 'Hot Dog', 'Fish Sandwich' ] # The list widget listwidget = qtw.QListWidget() listwidget.addItems(data) # The combobox combobox = qtw.QComboBox() combobox.addItems(data) self.layout().addWidget(listwidget) self.layout().addWidget(combobox)
Because both ...
Read now
Unlock full access