[PyQt] Master-detail relationship with plain QTableView tables (no SQL database)

Vadym Honcharuk intereco at gmail.com
Mon Jun 14 06:00:16 BST 2010


thank you, Mark!

one more question about applying filter in the context of QSortFilterProxyModel:

in MainForm() i created connection

self.connect(self.ui.TABLE#1.selectionModel(),
QtCore.SIGNAL("currentRowChanged(QModelIndex, QModelIndex)"),
self.TABLE#2Filter),

further (in simple way)

    def TABLE#2Filter(self):
	index = self.ui.srcTable.currentIndex()
	if index.isValid():
	
        # Received master table row unique number
            row = index.row()
	    srcCode = self.srcTableModel.data(self.srcTableModel.index(row,
SRCCODE)).toInt()[0]

        # Create QSortFilterProxyModel	
            filterFrmTable = QtGui.QSortFilterProxyModel()
	    filterFrmTable.setSourceModel(self.frmTableModel)
	    self.ui.frmTable.setModel(filterFrmTable)
	    filterFrmTable.setDynamicSortFilter(True)

        # Apply filter
   ------->filterFrmTable.???????????(srcCode)<----------

Question what method is analog of SQL setFilter() in context of
QSortFilterProxyModel?

Thanks in advance!

With best regards,
-vadym


2010/5/9 Mark Summerfield <list at qtrac.plus.com>:
> On 2010-05-08, Vadym Honcharuk wrote:
>> Hi to All,
>>
>> I need three tables with master-detail relationship one to other. I
>> made QTableView Model from Mark book and three vertical frame on one
>> page for it. How  possible connect these tables with master-detail
>> relationship? Examples are really welcome if possible...
>
> Hi Vadym,
>
> My book shows how to do master-detail in the context of a SQL database
> (e.g. pp. 463), but the same technique can be applied to any pair of
> table models.
>
> One approach is to connect the master table's selectionModel()'s
> currentRowChanged(QModelIndex,QModelIndex) signal to a custom slot.
> Then, in the custom slot you handle the populating of the detail table,
> for example, by filtering (which you can do with a sort/filter proxy
> model).
>
>
> --
> Mark Summerfield, Qtrac Ltd, www.qtrac.eu
>    C++, Python, Qt, PyQt - training and consultancy
>        "C++ GUI Programming with Qt 4" - ISBN 0132354160
>


More information about the PyQt mailing list