Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Combobox in a qtableview
Forum Update on Monday, May 27th 2025

Combobox in a qtableview

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 8.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mirshahabdin
    wrote on 12 Jul 2010, 23:45 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cyberbobs
      wrote on 13 Jul 2010, 07:11 last edited by
      #2

      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?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mirshahabdin
        wrote on 13 Jul 2010, 07:28 last edited by
        #3

        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);
        model->setTable("orderdetail");
        model->setEditStrategy(QSqlTableModel::OnManualSubmit);
        model->setRelation(model->fieldIndex("productId"),
        QSqlRelation("product", "id", "name"));
        model->select();

        ui->detailView->setModel(model);
        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!

        1 Reply Last reply
        0

        1/3

        12 Jul 2010, 23:45

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved