How to get rowvalue of selected combobox in Qtableview?
-
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.. -
Hi,
What is the current issue you have with your code ?
-
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 happeningSo 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 ??
-
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 happeningSo 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 ??
-
This:
connect(combo2, QOverload<int>::of(&QComboBox::currentIndexChanged), this,(&Gear_model::calR2));
is outside the loop so it connects the last widget only.