Qt World Summit: Submit your Presentation

Updating widget with QSqlTableModel

  • Hello,

    I have a database that look like this : db.png

    And my goal is to make a custom widget out of each row of the database

    For that I decided to use a QSqlTableModel and for each custom widget that I make, create a QWidgetMapper in whose purpose is to map a specific row to the QLabels of my custom widget like so

     m_dataMapper->addMapping(m_descriptionLabel, model->fieldIndex("description"), "text");
    m_dataMapper->addMapping(m_tagLabel, model->fieldIndex("tag"), "text");

    In my application, I allow the user to modify those label using QDialog, but one thing I am not able to do is update the database using my model and force it to update automatically the QLabels of my custom widget. Should I use a delegate ? What am I doing wrong

  • @Harsaith said in Updating widget with QSqlTableModel:

    Should I use a delegate ?

    1000 times yes

  • @VRonin
    But the delegate will now update the widgets unless and told force him to call setText() on the QLabels even though those qlabels are mapped to the model, am I correct ?

  • A delegate is not a widget. It paints itself using a paint() method that gets data directly from the model

Log in to reply