Combobox in a qtableview

  • I am implementing a qwidget which has a qtableview. I've used qsqlrelationaltablemodel to connect to my database. One of the tableview columns is a combobox which user can choose between some options. Every time the user select an option the rest of table should be filled with correct information. I can do this using the datachanged signal of my relationalmodel but the problem is that after user selection he/she needs to change the focus, e.g. by pushing return, so the model actually sees the changes and triggers the slot. I was wondering if there is any way that I can use a signal like currentindexchanged of combobox. Is there any one who has a solution, please?

  • How do you insert QComboBox to the view? You use delegate, index widget or something else?

    In a case, reloading a data when changing one of the data fields in the model is not fully correct in my opinion. Could you show a screenshot or a code snippet?

  • I used delegate. Here is a part of the code, ui is just my user interface in which detailview (a qtableview) is defined. I have an order table and a product table in mysql database. What I am trying to do is when the user inserts a new order which is basically a row in my qtableview and selects one of the products from the combobox then the rest of information such as product unit price, etc. should pops up in the right column. Right now I can do it by @connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataChanged(QModelIndex,QModelIndex)));@ but for this signal to work the user need to change the focus which is a bit odd.

    Thanks a lot for the response!

    @model = new QSqlRelationalTableModel(this);
    QSqlRelation("product", "id", "name"));

    ui->detailView->setItemDelegate(new QSqlRelationalDelegate(ui->detailView));@

    P.S. I can send you the whole code but there are multiple files and a lot of different parts that might make it harder to figure out what's what. But let me know if you need the whole thing. Thanks again!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.