[PyQt] How to update a relationModel
Stefano Z.
mie.iscrizioni at gmail.com
Mon Jun 29 16:44:30 BST 2009
hello
i need to know how to update a combobox linked to a datawidgetmapper
when the table in relation with the mapper model is modified by en external
application.
code:
def setupModels(self):
"""
Initialize all the application models
"""
# setup masterModel
self.mModel = QSqlRelationalTableModel(self)
self.mModel.setTable(QString(" fattmaster"))
self.mModel.setSort(MDATA, Qt.AscendingOrder)
self.mModel.setRelation(MIDCLI, QSqlRelation("clienti",
"id", "ragsoc"))
self.mModel.setRelation(MIDTDOC, QSqlRelation("tipofatt",
"id", "tfatt"))
self.mModel.select()
def setupMappers(self):
'''
Initialize all the application mappers
'''
self.mapper = QDataWidgetMapper(self)
self.mapper.setSubmitPolicy(QDataWidgetMapper.ManualSubmit)
self.mapper.setModel(self.mModel)
self.mapper.setItemDelegate(QSqlRelationalDelegate(self))
self.mapper.addMapping(self.dateEdit, MDATA)
self.mapper.addMapping(self.fattLineEdit, MDOC)
relationModel = self.mModel.relationModel(MIDTDOC)
relationModel.setSort(1, Qt.AscendingOrder)
relationModel.select()
self.tipoFattComboBox.setModel(relationModel)
self.tipoFattComboBox.setModelColumn(relationModel.fieldIndex("tfatt"))
self.mapper.addMapping(self.tipoFattComboBox, MIDTDOC)
relationModel = self.mModel.relationModel(MIDCLI)
relationModel.setSort(CRAGSOC, Qt.AscendingOrder)
relationModel.select()
self.cliComboBox.setModel(relationModel)
self.cliComboBox.setModelColumn(relationModel.fieldIndex("ragsoc"))
self.mapper.addMapping(self.cliComboBox, MIDCLI)
self.mapper.addMapping(self.tipoPagLineEdit, MPAG)
self.mapper.addMapping(self.cauLineEdit, MCAU)
self.mapper.addMapping(self.noteLineEdit, MNOTE)
self.mapper.toFirst()
def editCustomers(self):
# call the 'clienti' table editor
subprocess.call(['python',os.path.join(os.path.dirname(__file__),
"clienti.py")])
# update all controls
self.setupModels()
self.setupMappers()
self.setupTables()
-------------------------
now, if an external application change (eg add a new record on 'clienti'
table) the 'clienti' table,
how to update the self.cliComboBox control ?
actually i'm 'rebuilding' all controls as you can see on the editCustomers
method, is this the only wahy to update the combobox control ?
thanks.
--
"Io oso fare tutto cio' che puo' essere degno di un uomo, chi osa di piu'
non lo e'"
http://blog.zamprogno.it
http://riparazioni.zamprogno.it
http://www.archlinux.it
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090629/e4a4665a/attachment.html
More information about the PyQt
mailing list