How to get the row value from Qtable widget
- 
wrote on 13 Jun 2019, 11:43 last edited by ManiRon
Actually i am inserting combo box in one column on my table and when one of the combo box from the table is selected i want to get the row value . How this can be done ?
void MainWindow::on_tableWidget_clicked(const QModelIndex &index)
{
qDebug("ROW %d",index.row());
}I tried something like this but it didnt give the row value where i have inserted the combo box and from other places it was returning the row value
 - 
Actually i am inserting combo box in one column on my table and when one of the combo box from the table is selected i want to get the row value . How this can be done ?
void MainWindow::on_tableWidget_clicked(const QModelIndex &index)
{
qDebug("ROW %d",index.row());
}I tried something like this but it didnt give the row value where i have inserted the combo box and from other places it was returning the row value
wrote on 13 Jun 2019, 12:15 last edited byvoid MainWindow::on_tableWidget_clicked(const QModelIndex &index) { qDebug() << "ROW: " << index.row(); qDebug() << "TEXT: " << itemFromIndex(index).text(); if(index.column() == COLUMN_COMBOBOX) //Check it is the "ComboBox" column //Do something with value } - 
void MainWindow::on_tableWidget_clicked(const QModelIndex &index) { qDebug() << "ROW: " << index.row(); qDebug() << "TEXT: " << itemFromIndex(index).text(); if(index.column() == COLUMN_COMBOBOX) //Check it is the "ComboBox" column //Do something with value } - 
@Gojir4 when i click on the combo box nothing is triggred from the QTablewidget so i couldnt find the row value for that
wrote on 13 Jun 2019, 13:36 last edited by Gojir4@ManiRon Ok, here is another approach (I didn't test the code, it mays have errors)
//At initilization QComboBox *cb = new QComboBox; cb.setProperty("row", row); connect(cb, qOverload<int>(&QComboBox::currentIndexChanged), this, &MainWindow::onCbIndexChanged) myTableWidget->setCellWidget(row, column, cb); //... //On Combo Box Index changed void MainWindow::onCbIndexChanged(int index){ QObject *cb = sender(); const int row = cb->property("row"); int comboBoxSelectionIndex = index; qDebug() << "ROW: " << row; qDebug() << "Index: " << index << " value: " << cb.currentText(); }inspired from here: https://www.qtcentre.org/threads/66573-How-to-get-signal-when-checkbox-in-table-cell-changed
 - 
Hi
Just as a note
Using a combo box delegate instead of setCellWidget have better performance and overall just feels
nicer than a floating widget. (IMHO)
basic example:
https://github.com/daviddoria/QtExamples/blob/master/Delegates/ComboBoxDelegate/ComboBoxDelegate.cpp - 
@Gojir4 when i click on the combo box nothing is triggred from the QTablewidget so i couldnt find the row value for that
wrote on 13 Jun 2019, 17:23 last edited by@ManiRon said in How to get the row value from Qtable widget:
when i click on the combo box nothing is triggred
because
setIndexWidgetis PURE EVILFollow @mrjj 's suggestion. Ther's also a wiki page on this topic: https://wiki.qt.io/Combo_Boxes_in_Item_Views
 - 
Hi
Just as a note
Using a combo box delegate instead of setCellWidget have better performance and overall just feels
nicer than a floating widget. (IMHO)
basic example:
https://github.com/daviddoria/QtExamples/blob/master/Delegates/ComboBoxDelegate/ComboBoxDelegate.cpp - 
wrote on 18 Jun 2019, 07:20 last edited by
 
1/8