Results 1 to 3 of 3

Thread: Displaying complex info when using QSqlRelationalTableModel

  1. #1
    Join Date
    Jun 2010
    Location
    Cincinnati, Ohio, USA
    Posts
    92
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question Displaying complex info when using QSqlRelationalTableModel

    have two tables: Session and Image. The Session table has a foreign key (FK) to the Image table, Image_Id. The Image table has a number of fields, the two I am interested in is the blob that is the image and the field that is the name of the image.

    I want to do something like:

    sessionModel->setRelation(2, QSqlRelation("Image", "Image_Id", "<both image and name>"));

    So the combo box shows both the image and the name. How is this done?

    Sam

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Displaying complex info when using QSqlRelationalTableModel

    If your question is only about displaying the image and the name in a line in a combobox:

    Use a standard item model.
    For each item in the model, set the data to the correct item role
    Qt::DisplayRole -> the text being displayed: name of the image
    Qt::DecorationRole -> the icon of the image

  3. #3
    Join Date
    Jun 2010
    Location
    Cincinnati, Ohio, USA
    Posts
    92
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Displaying complex info when using QSqlRelationalTableModel

    part of my objective is to get as much of the Qt framework doing as much of the database interaction as I can, so I can code less and implement more

    What I have so far is:

    Qt Code:
    1. _photoSessionModel = new QSqlRelationalTableModel(this);
    2. _photoSessionModel->setTable("PHOTO_SESSION");
    3. _photoSessionModel->setEditStrategy(QSqlTableModel::OnRowChange);
    4.  
    5. connect(_photoSessionModel, SIGNAL(beforeUpdate(QSqlRecord&)), this, SLOT(on_photoSessionModel_beforeInsert(QSqlRecord&)));
    6. connect(_photoSessionModel, SIGNAL(beforeUpdate(int,QSqlRecord&)), this, SLOT(on_photoSessionModel_beforeUpdate(int,QSqlRecord&)));
    7.  
    8. _photoSessionMapper = new QDataWidgetMapper(this);
    9. _photoSessionMapper->setModel(_photoSessionModel);
    10. _photoSessionMapper->setItemDelegate(new QSqlRelationalDelegate(this));
    11.  
    12. _photoSessionMapper->addMapping(ui.directoryImageComboBox, _photoSessionModel->fieldIndex("PHOTO_SESSION_IMAGE_ID"));
    To copy to clipboard, switch view to plain text mode 

    The goal here is to add a QSqlRelation to the _photoSessionModel so that when the filter is changed on the model, the comboBox will do two things:

    1: Change the list of images that show up in the combo box
    2: Select the correct image, based on the id in the model.

    What I do NOT want to have to do is update the model of the images, I am looking for Qt to do that for me. I am OK with creating the the image model, I am just looking for the Qt framework to do the updating when the _photoSessionModel.

    The development I am doing is incremental right now, step one is getting this basic functionality working. Later I am going to want to come in and really fine tune how things are displayed, position, and what get highlighted, aka not the image itself, but just the name. So ideally I would like to create either a model or a delegate to display the images. I am not seeing anything on the QSqlRelation to allow me access to change the model. Can I simply use the default behavior of the QSqlRelation and then change the delegate on the comboBox to achieve what I am after?

    Sam

    the filter on the _photoSessionModel to the target session and have the model

Similar Threads

  1. Replies: 1
    Last Post: 6th July 2010, 15:40
  2. Complex number
    By nbo10 in forum Qt Programming
    Replies: 1
    Last Post: 4th April 2009, 06:44
  3. complex calculations with qt
    By gt.beta2 in forum Newbie
    Replies: 5
    Last Post: 7th February 2009, 23:55
  4. Complex QCompleter
    By Amouse in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2008, 22:39
  5. Complex Numbers
    By Max Yaffe in forum Qt Programming
    Replies: 2
    Last Post: 24th May 2007, 17:40

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
  •  
Qt is a trademark of The Qt Company.