Results 1 to 2 of 2

Thread: QSqlRelationalDelegate (ComboBox) id on first show

  1. #1
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default QSqlRelationalDelegate (ComboBox) id on first show

    Hi,

    I have a relationalTableModel with one relation

    Qt Code:
    1. cxcModel = new QSqlRelationalTableModel;
    2. cxcModel->setTable("crop_x_cultivar");
    3. cxcModel->setHeaderData(1, Qt::Horizontal, tr("Frucht"));
    4. cxcModel->setHeaderData(2, Qt::Horizontal, tr("Sorte"));
    5. cxcModel->setRelation(1, QSqlRelation("crop", "crop_id", "crop_name"));
    6. cxcModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    7. cxcModel->select();
    8. ui.tableViewCxC->setModel(cxcModel);
    9. ui.tableViewCxC->hideColumn(0);
    10. ui.tableViewCxC->setItemDelegate(new QSqlRelationalDelegate(ui.tableViewCxC));
    To copy to clipboard, switch view to plain text mode 

    I add data with a form (see sreenshots) and the user can submit the data by pressing a save button. When pressing the "add" button i only insert a record in the cxcModel. When the "add" button is pressed the view shows the crop_id but not the crop_name. When i activate the cell or press "save" the right name (via the foreign key) is shown.
    From the hidden column of the comboBox i get the crop_id

    Qt Code:
    1. void BasicDataDialog::on_toolButtonAddCultivar_clicked()
    2. {
    3. if(!ui.lineEditCultivar->text().isEmpty()){
    4. QSqlRecord rec = cxcModel->record();
    5. idx = cropModel->index(ui.comboBoxCrop->currentIndex(), 0, QModelIndex());
    6. rec.setNull(0);
    7. rec.setValue(1, cropModel->data(idx).toInt());
    8. rec.setValue(2, ui.lineEditCultivar->text());
    9. if(cxcModel->insertRecord(-1, rec));
    10. ui.pushButtonSave->show();
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    Any idea how to force the delegate to show the name (instead of the id) while the data is still cached? thx
    Attached Images Attached Images
    • File Type: jpg 1.jpg (30.9 KB, 23 views)
    • File Type: jpg 2.jpg (33.9 KB, 20 views)

  2. #2
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: QSqlRelationalDelegate (ComboBox) id on first show

    it might be a bug ...

    hm, has anyone an idea how to work around this?

Similar Threads

  1. unable to hide combobox or spinbox in toolbar
    By Sandip in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2008, 11:52
  2. Replies: 2
    Last Post: 18th March 2008, 15:38
  3. [Qt 4.3.1]A problem with combobox style
    By Tamara in forum Qt Programming
    Replies: 3
    Last Post: 19th September 2007, 10:49
  4. Combobox Signals
    By b1 in forum Qt Programming
    Replies: 3
    Last Post: 1st August 2006, 10:21
  5. Filling combobox from database
    By Philip_Anselmo in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2006, 17:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.