Lesson 03 · Desktop Apps with Python & Qt
Desktop: Model/View Programming
Stop copying data into widgets by hand: learn Qt's model/view architecture - a QStringListModel in a QListView, a custom QAbstractTableModel with editable cells, and live search with QSortFilterProxyModel.
Prerequisites: Desktop: Signals, Slots & Events
Learning objectives
By the end of this lesson, you will be able to:
- Explain the problem model/view solves and why keeping data inside widgets does not scale
- Display a QStringListModel in a QListView and describe what each half owns
- Subclass QAbstractTableModel, implementing rowCount, columnCount, data and headerData with Qt.ItemDataRole.DisplayRole
- Make a model editable with flags and setData, and announce changes with dataChanged
- Filter any model live with a QSortFilterProxyModel wired to a search box