Results 1 to 2 of 2

Thread: QSqlRelationalTableModel and editable QComboBox

  1. #1
    Join Date
    Oct 2009
    Posts
    65
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSqlRelationalTableModel and editable QComboBox

    Hello to everybody,
    I read some post on this forum but i didn't found any answer to my problem. I hope you could help me
    I've a table (Carichi) with a Foreing key of an other table (Colori), so I create my QSqlRelationalTableModel;
    Qt Code:
    1. //Definizione del modello principale
    2. myModel = new QSqlRelationalTableModel(this);
    3. myModel->setTable("Carichi");
    4. myModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    To copy to clipboard, switch view to plain text mode 
    Now I create the relationModel to a new QSqlTableModel:
    Qt Code:
    1. int custIndexCol=myModel->fieldIndex("CodCol");
    2. myModel->setRelation(custIndexCol,QSqlRelation("Colori","idColori","Colore"));
    3.  
    4. //Definizione del modello del colore
    5. mdlCol = myModel->relationModel(custIndexCol);
    6. mdlCol->setEditStrategy(QSqlTableModel::OnManualSubmit);
    7. ui->cboColore->setModel(mdlCol);
    8. ui->cboColore->setModelColumn(mdlCol->fieldIndex("Colore"));
    9. ui->cboColore->setItemDelegate(new QSqlRelationalDelegate(ui->cboColore));
    To copy to clipboard, switch view to plain text mode 

    Now I've all my components (also a QComboBox to display items).

    Now I'd like that the user can edit the QComboBox (setting it editable isn't it?) also adding a new element (that not is into Colori) and adding it to base table Colori, so it create the element for the foreign key and the table Carichi can save the new element created.

    I thought that setting QComboBox editable could be enought, seen the model linked by setModel(), but, I understood that isn't!!

    I hope I explain correctly enought my problem

    Thanks a lot for your time

    Michele

  2. #2
    Join Date
    Oct 2009
    Posts
    65
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlRelationalTableModel and editable QComboBox

    Hi guys, good news
    I search on the net and I found some ideas nearly a QSqlRelationalDelegate, so I create a subclass and I modify the realationaltablemodel Qt example to test it. I attach my example so you can test it.

    If you add a new city to Oslo, Munich and San Jose such as "New York", the city will be added to the list, but not immediatly selected for the employee record. But, if you select "New York" from the list, it will be saved into employee record

    How can avoid the double selection of the city and select it for the employee record, at the first confirm after the adding of the city?

    Thanks a lot for your time.

    Michele
    Attached Files Attached Files

Similar Threads

  1. Replies: 2
    Last Post: 29th December 2012, 15:14
  2. Replies: 0
    Last Post: 15th September 2010, 13:10
  3. Detecting Enter in an editable QComboBox
    By wconstan in forum Newbie
    Replies: 2
    Last Post: 28th December 2009, 07:43
  4. Editable QComboBox with QItemDelegate
    By Jmgr in forum Qt Programming
    Replies: 11
    Last Post: 10th December 2008, 10:21
  5. Return key in an editable QComboBox accepts a QDialog
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 10th July 2008, 16:56

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.