I'm using a QStyledItemDelegate to implement a custom editor for a subset of columns in a QSqlRelationalTableView.

The custom editor widget needs some data that's not in the underlying model. So, I have code that queries other Sql tables to get the data needed to present the custom editor widget.

The records from the other tables are used to populate a comboBox and set the state of some pushbuttons. Selecting a different item in the combobox isn't supposed to change anything but the currentText of the combobox and the related data in the underlying model cell. The records get associated with the new combobox selection.

I'm wondering whether this code belongs in the createEditor or in setEditorData method. Or does it matter?

It seems like both are always called when a cell in the table is edited, first the createEditor, then the SetEditorData.

The example in the Qt docs (http://qt-project.org/wiki/Combo_Boxes_in_Item_Views) populates the combobox in the createEditor method, then does a selection of the combobox in the setEditorData based on what's in the underlying data model.

In my case, I need the data from the underlying data not only to select the current item in the combobox, but also for queries to other Sql queries. to get the button states. It seems like it will work either place--are there considerations for where to put the code?

Thanks,

Dave Thomas