Hi Community,
I'm having trouble with a QTableWidget that's part of a dialog.
The table has 6 columns; The cells belonging to the first columns contains only text while the others contains a QComboBox widget (each combobox has 3 text items).
In my code I need to detect which combobox widget was changed so I connected the cellChanged signal to my slot in this way:
connect( tableBiasRadar_, SIGNAL(cellChanged(int, int)), this, SLOT(tableBiasRadar__cellChanged(int, int)));
connect( tableBiasRadar_, SIGNAL(cellChanged(int, int)), this, SLOT(tableBiasRadar__cellChanged(int, int)));
To copy to clipboard, switch view to plain text mode
And the relative slot:
void OtrParametersDialogCtrl::tableBiasRadar__cellChanged(int row, int col)
{
std::cerr << "[DEBUG] OtrParametersDialogCtrl::tableBiasRadar__valueChanged : Row: " << row << " Col: " << col << std::endl;
// If the column changed is the time offset, change all other modes of the radar
if (static_cast<RadarBiasTableColums_>(col) != radarBiasTableTimeOffsetC_)
{
return;
}
// Get the value set by the user
QComboBox *item
= qobject_cast<QComboBox
*>
(tableBiasRadar_
->cellWidget
(row, col
));
if (item == nullptr)
{
return;
}
// Look for the radar that is being edited by this item
const int radarId = tableBiasRadar_Column2RadarId_[row];
// Change the value of the combo box in all other rows that edit this item
for (size_t i = 0; i < tableBiasRadar_Column2RadarId_.size(); ++i)
{
if (i != static_cast<size_t>(row) && tableBiasRadar_Column2RadarId_[i] == radarId)
{
QComboBox *itemToBeModified
= qobject_cast<QComboBox
*>
(tableBiasRadar_
->cellWidget
(static_cast<int>
(i
), col
));
if (itemToBeModified != nullptr)
{
itemToBeModified->setCurrentIndex(item->currentIndex());
}
}
}
}
void OtrParametersDialogCtrl::tableBiasRadar__cellChanged(int row, int col)
{
std::cerr << "[DEBUG] OtrParametersDialogCtrl::tableBiasRadar__valueChanged : Row: " << row << " Col: " << col << std::endl;
// If the column changed is the time offset, change all other modes of the radar
if (static_cast<RadarBiasTableColums_>(col) != radarBiasTableTimeOffsetC_)
{
return;
}
// Get the value set by the user
QComboBox *item = qobject_cast<QComboBox*>(tableBiasRadar_->cellWidget(row, col));
if (item == nullptr)
{
return;
}
// Look for the radar that is being edited by this item
const int radarId = tableBiasRadar_Column2RadarId_[row];
// Change the value of the combo box in all other rows that edit this item
for (size_t i = 0; i < tableBiasRadar_Column2RadarId_.size(); ++i)
{
if (i != static_cast<size_t>(row) && tableBiasRadar_Column2RadarId_[i] == radarId)
{
QComboBox *itemToBeModified = qobject_cast<QComboBox*>(tableBiasRadar_->cellWidget(static_cast<int>(i), col));
if (itemToBeModified != nullptr)
{
itemToBeModified->setCurrentIndex(item->currentIndex());
}
}
}
}
To copy to clipboard, switch view to plain text mode
It doesn't matter which combobox I change, I always get the same output:
[DEBUG] OtrParametersDialogCtrl::tableBiasRadar__valueChan ged : Row: 0 Col: 0
[DEBUG] OtrParametersDialogCtrl::tableBiasRadar__valueChan ged : Row: 1 Col: 0
[DEBUG] OtrParametersDialogCtrl::tableBiasRadar__valueChan ged : Row: 2 Col: 0
[DEBUG] OtrParametersDialogCtrl::tableBiasRadar__valueChan ged : Row: 3 Col: 0
[DEBUG] OtrParametersDialogCtrl::tableBiasRadar__valueChan ged : Row: 4 Col: 0
[DEBUG] OtrParametersDialogCtrl::tableBiasRadar__valueChan ged : Row: 5 Col: 0
[DEBUG] OtrParametersDialogCtrl::tableBiasRadar__valueChan ged : Row: 6 Col: 0
[DEBUG] OtrParametersDialogCtrl::tableBiasRadar__valueChan ged : Row: 7 Col: 0
[DEBUG] OtrParametersDialogCtrl::tableBiasRadar__valueChan ged : Row: 8 Col: 0
[DEBUG] OtrParametersDialogCtrl::tableBiasRadar__valueChan ged : Row: 9 Col: 0
[DEBUG] OtrParametersDialogCtrl::tableBiasRadar__valueChan ged : Row: 10 Col: 0
[DEBUG] OtrParametersDialogCtrl::tableBiasRadar__valueChan ged : Row: 11 Col: 0
[DEBUG] OtrParametersDialogCtrl::tableBiasRadar__valueChan ged : Row: 12 Col: 0
[DEBUG] OtrParametersDialogCtrl::tableBiasRadar__valueChan ged : Row: 13 Col: 0
I would like to have a help in discovering why I always get the column 0 (the column 0 does not contain any combobox, only text) even when I change the combobox of other columns and why I get the output of all the rows also if I change only 1 row.
The look&feel of the dialog looks correct, all the cells belonging to column 1 to 6 contains the combobox, so I really don't understand what's happening here. I am using 5.9.7, unfortunately this is a constraint.
Could it be a bug in this Qt version?
I hope to get help.
Franco
Bookmarks