waynew
22nd August 2010, 02:30
Seems like this has been beat to death in past posts, but I can't seem to figure out how to apply a solution to my problem.
I have a table view in a form built with designer. 2 columns have item delegates to provide combo boxes to limit the choices of entry values. The problem I have is in trying to limit the choices of the second column based on what is chosen from the combo box in the first column. The solution seemed to be to emit a signal from column 1 when the value was edited. Then receive the value in a slot in the column 2 delegate and use the received value to limit the combo box choices in column 2.
Problem is that the setModelData function in column 1 won't work unless it is declared const. Then you can't emit a signal from it. In one post Wysota said, declare the slot const too. Tried that but it still gets the same compile error about discards qualifiers.
Here is the relevant part of the code - column 1 delegate with signal:
void ModeDelegate::setModelData(QWidget* editor, QAbstractItemModel* model,
const QModelIndex& index) const
{
QComboBox* comboBox = static_cast<QComboBox*>(editor);
QString value = comboBox->currentText();
qDebug() << "mode delegate data is " << value;
emit modeChanged(value); // CAUSES THE COMPILE ERROR
model->setData(index, value, Qt::EditRole);
}
Here is the slot in column 2 delegate:
void FilterDelegate::getMode(QString value) const
{
qDebug() << "mode value received is " << value;
}
Is there a way around this, or another way I can get the column 1 selected value to column 2?
I have a table view in a form built with designer. 2 columns have item delegates to provide combo boxes to limit the choices of entry values. The problem I have is in trying to limit the choices of the second column based on what is chosen from the combo box in the first column. The solution seemed to be to emit a signal from column 1 when the value was edited. Then receive the value in a slot in the column 2 delegate and use the received value to limit the combo box choices in column 2.
Problem is that the setModelData function in column 1 won't work unless it is declared const. Then you can't emit a signal from it. In one post Wysota said, declare the slot const too. Tried that but it still gets the same compile error about discards qualifiers.
Here is the relevant part of the code - column 1 delegate with signal:
void ModeDelegate::setModelData(QWidget* editor, QAbstractItemModel* model,
const QModelIndex& index) const
{
QComboBox* comboBox = static_cast<QComboBox*>(editor);
QString value = comboBox->currentText();
qDebug() << "mode delegate data is " << value;
emit modeChanged(value); // CAUSES THE COMPILE ERROR
model->setData(index, value, Qt::EditRole);
}
Here is the slot in column 2 delegate:
void FilterDelegate::getMode(QString value) const
{
qDebug() << "mode value received is " << value;
}
Is there a way around this, or another way I can get the column 1 selected value to column 2?