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. How to get rowvalue of selected combobox in Qtableview?
Forum Updated to NodeBB v4.3 + New Features

How to get rowvalue of selected combobox in Qtableview?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 530 Views 3 Watching
  • 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.
  • N Offline
    N Offline
    n-2204
    wrote on last edited by n-2204
    #1

    Hi,
    I have Qtableviews,,i have added combobox in table2 and values in combobox getting from table1 col0, so when user select item in combo2,i need to get the row value of selected item ? 1->How can i do using indexwidget ??
    2->after getting row value then i can compare the combobox text and perform the calculation..
    As what i shared is working but when user select same value in 2 rows (diff)combobox then its not working(not getting data in 2 time). .

    void Gear_model::calR2() {
    QAbstractItemModel* table1 = ui.tableView->model();
    QAbstractItemModel* table2 = ui.tableView_2->model();
    QComboBox* combo2;
    QString col2;
    for (int irowsl = 0, maxI = table2->rowCount(); irowsl < maxI; ++irowsl)
    {
        const QModelIndex idx1 = table2->index(irowsl, 2);
        combo2 = qobject_cast<QComboBox*>(ui.tableView_2->indexWidget(idx1)); 
        col2 = combo2->currentText();
        for (int irowsM = 0, maxI = table2->rowCount(); irowsM < maxI; ++irowsM) {
            qDebug() << "combo2 =" << col2;                                        
            if (col2 == table1->data(table1->index(irowsM, 0)).toString()) {
                double pitchradius2 = table1->data(table1->index(irowsM, 6)).toDouble();
                table2->setData(table2->index(irowsl, 10), radius2);
                qDebug() << "R2 =" << col2 << radius2;
            }
        }
     }
    }  
    connect(combo2, QOverload<int>::of(&QComboBox::currentIndexChanged), this,(&Gear_model::calR2));
    

    Cannot figure out how to get the selected value of the combobox for each row ?
    Thankyou..

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What is the current issue you have with your code ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • N Offline
        N Offline
        n-2204
        wrote on last edited by n-2204
        #3

        62d91f1d-e673-4167-8a43-65de0049ca99-image.png
        50f554ac-1f4a-4935-b6ab-00283c0c23b2-image.png
        Issue is when i select a item value second time or multiple time , in picture 2 & 3 entry as b . so here 3 entry is not updating in my col2,,
        col2 = combo2->currentText();
        and as i shared code that calculation not happening

        So i want to get rowvalue of selected combobox from my table2 so then based on rowvalue i get text and then do comparison with my table1 col0 data ??

        kshegunovK 1 Reply Last reply
        0
        • N n-2204

          62d91f1d-e673-4167-8a43-65de0049ca99-image.png
          50f554ac-1f4a-4935-b6ab-00283c0c23b2-image.png
          Issue is when i select a item value second time or multiple time , in picture 2 & 3 entry as b . so here 3 entry is not updating in my col2,,
          col2 = combo2->currentText();
          and as i shared code that calculation not happening

          So i want to get rowvalue of selected combobox from my table2 so then based on rowvalue i get text and then do comparison with my table1 col0 data ??

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #4

          Don't use setIndexWidget, use a delegate to create the editor.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          1
          • N Offline
            N Offline
            n-2204
            wrote on last edited by
            #5

            Actually i have 7-8 rows only ,,so using setindexwidget()

            1 Reply Last reply
            0
            • N Offline
              N Offline
              n-2204
              wrote on last edited by
              #6

              How can i get the selected combobox row value ?
              or in loops i can change something so if i select a combobox item value multiple item it should work?

              1 Reply Last reply
              0
              • kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #7

                This:

                connect(combo2, QOverload<int>::of(&QComboBox::currentIndexChanged), this,(&Gear_model::calR2));
                

                is outside the loop so it connects the last widget only.

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply
                2
                • N Offline
                  N Offline
                  n-2204
                  wrote on last edited by n-2204
                  #8

                  Thank you .
                  I found the solution
                  after combo2
                  I added if (combo2!=NULL) {
                  //my previous code
                  }

                  1 Reply Last reply
                  0

                  • Login

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