[PyKDE] QSqlPropertyMap

Phil Thompson phil at riverbankcomputing.co.uk
Tue Feb 24 23:03:00 GMT 2004


On Tuesday 24 February 2004 21:12, Torsten Bielen wrote:
> Hi,
>
> I want to use my own QSqlPropertyMap in a form to install a customized
> editor. Is there any example how to use QSqlPropertyMap in python. I wrote
> the code below but it doesn't work.
>
> class IdEditor(QWidget):
>    """
>    custom editor for a combo box (without any functionality yet)
>    """
>     def __init__(self, cmbBox):
>         QWidget.__init__(self)
>         self.cmbBox = cmbBox
>         self._itemId = 0
>
>     def itemId(self):
>         debug("itemId called")
>     def setItemId(self, id):
>         debug("setItemId called")
>
>
> ... ...
>         self.sqlPropMap = QSqlPropertyMap()
>         self.sqlPropMap.insert("IdEditor", "itemId")
>         self.sqlForm = QSqlForm(self, "frmAccount_SqlForm")
>         self.sqlForm.installPropertyMap(self.sqlPropMap)
>
>         self.sqlForm.insert(self.lineEditLoginName, "login_name")
>         self.sqlForm.insert(self.lineEditFullName, "full_name")
>         self.sqlForm.insert(self.checkBoxLocked , "locked")
>         self.sqlForm.insert(self.textEditDesc, "long_desc")
>         self.sqlForm.insert(IdEditor(self.comboBoxPrimaryGroup),
> 					"primary_group")
>
> In the form is a combo box. I want to translate ids stored in the database
> into strings (group names). My idea was to wrap the combo box with my own
> editor and translate it to strings stored in the combo box.

An obvious problem is that the IdEditor instance will get garbage collected 
immediately. Try keeping another reference to it.

Phil




More information about the PyQt mailing list