[Qt-interest] QSqlRelationalDelegate and QDataWidgetMapper
Christian Gagneraud
cgagneraud at techworks.ie
Tue Feb 9 00:30:44 CET 2010
On 02/08/2010 11:04 PM, Christian Gagneraud wrote:
> On 02/08/2010 09:26 PM, Christian Gagneraud wrote:
>> Hi There,
>>
>> I'm using a QTableView with a QSqlRelationalTableModel and a
>> QSqlRelationalDelegate, this works great.
>> In another QDialog, I'm using as well a QDataWidgetMapper, and it
>> doesn't seems to work when there is a relation set-up in the model (I
>> got an empty field)
>> I tried to use on my form a QLineEdit or a QComboBox, I tried to
>> set-up the item delegate of the mapper as well with a
>> QSqlRelationalDelegate but none of these have worked so far.
>>
>> Is the QSqlRelationalDelegate supposed to work seamlessly with a
>> QTableView and QDataWidgetMapper? Or is it me that do something wrong?
>
> OK, I've found my error:
> After a relation is set via setRelation(), the column is rename
> according to the "mappedtablename_displayedcolumnname"...and I was
> still using the original column name to set up my QDataWidgetMapper,
> that's why it didn't work....
> But that's not all! It's still doesn't work with a combo box!
> If I use a QLineEdit, then I get the right value. But I would like to
> have the same QComboBox as in the TableView...
OK, so I found a way, but I'm not convinced this is the way to go:
I set up myself the combo box before calling mapper->addMapping():
int compidx = model->fieldIndex("company_name");
QSqlTableModel* relmodel=model->relationModel(compidx);
int nameidx = relmodel->fieldIndex("name");
QComboBox *combo = ui->companyEdit;
combo->setModel(relmodel);
combo->setModelColumn(nameidx);
mapper->addMapping(combo, compidx);
mapper->setItemDelegate(new SqlRelationalDelegate(mapper));
There should be a way to let the mapper create and/or initialise the
editing widget thought...
If anyone has suggestion on this matter...
Chris
>
> Chris
>
>
>
>>
>> Any help or point-out appreciated.
>>
>> Regards,
>> Chris
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list