QSqlRelationalTableModel, QSortFilterProxyModel and QDataWidgetMapper

Heads up! You've already completed this tutorial.

friedhelm | 2021-04-20 15:05:30 UTC | #1

There are two tables with one to many relation companies and resources. The models above works fine with table views and combobox for the company names for the index in the second table. For an selected row the form will be correct filled via the the QDataWidgetMapper.

Now I extend the game and extend it with sorting for columns in the tables

self.proxyModel = QSortFilterProxyModel() self.proxyModel.setSourceModel(self.model) self.setSortingEnabled(True) self.setModel(self.proxyModel)

This gives two Side effects:

  • The combobox for the company names are not in the second table
  • If I sort one of the table and select a row for editing, I got an wrong rowid and as result a form for an wrong dataset

How can I fix the 'row' disaster?


The complete guide to packaging Python GUI applications with PyInstaller.
[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]
Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

QSqlRelationalTableModel, QSortFilterProxyModel and QDataWidgetMapper was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt.